Extract similar fields from Transaction and NFT classes

This commit is contained in:
Aelita4 2023-01-26 19:57:01 +01:00
parent a6728214b2
commit b791bef037
3 changed files with 15 additions and 12 deletions

View File

@ -0,0 +1,9 @@
package pl.mikorosa.dziecoin;
public abstract class BlockData {
protected String owner;
public String getOwner() {
return this.owner;
}
}

View File

@ -1,8 +1,7 @@
package pl.mikorosa.dziecoin;
public class NFT {
public class NFT extends BlockData {
private String contract;
private String owner;
private String data;
public NFT(String owner, String data) {
@ -23,10 +22,6 @@ public class NFT {
return contract;
}
public String getOwner() {
return owner;
}
public String getData() {
return data;
}

View File

@ -1,18 +1,17 @@
package pl.mikorosa.dziecoin;
public class Transaction {
private String sender;
public class Transaction extends BlockData {
private String recipient;
private int amount;
public Transaction(String sender, String recipient, int amount) {
this.sender = sender;
this.owner = sender;
this.recipient = recipient;
this.amount = amount;
}
public String getSender() {
return sender;
return owner;
}
public String getRecipient() {
@ -26,7 +25,7 @@ public class Transaction {
@Override
public String toString() {
return "Transaction{" +
"sender='" + sender + '\'' +
"sender='" + owner + '\'' +
", recipient='" + recipient + '\'' +
", amount=" + amount +
'}';