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; package pl.mikorosa.dziecoin;
public class NFT { public class NFT extends BlockData {
private String contract; private String contract;
private String owner;
private String data; private String data;
public NFT(String owner, String data) { public NFT(String owner, String data) {
@ -22,11 +21,7 @@ public class NFT {
public String getContract() { public String getContract() {
return contract; return contract;
} }
public String getOwner() {
return owner;
}
public String getData() { public String getData() {
return data; return data;
} }

View File

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