Skip to content

Commit

Permalink
Merge pull request #18 from solvena/7-factory
Browse files Browse the repository at this point in the history
Add Factory for Transaction
  • Loading branch information
elisab3 authored May 24, 2026
2 parents 3f2aacc + 0f452a2 commit dcd5041
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/Model/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public Transaction buy(String symbol, BigDecimal quantity, Player player) {
// lager en ny "andel" basert på nåværende salgspris
Share shareToBuy = new Share(stock, quantity, stock.getSalesPrice());

// oppretter kjøpstransaksjonen for den uka
Purchase purchase = new Purchase(shareToBuy, this.week);
// oppretter kjøpstransaksjonen for den uka via fabrikken
Transaction purchase = TransactionFactory.createPurchase(shareToBuy, this.week);

// committer til player
purchase.commit(player);
Expand All @@ -81,8 +81,8 @@ public Transaction sell(Share share, Player player) {
return null;
}

// oppretter salgstransaksjonen for den uka
Sale sale = new Sale(share, this.week);
// oppretter salgstransaksjonen for den uka via fabrikken
Transaction sale = TransactionFactory.createSale(share, this.week);

// commiter til player
sale.commit(player);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/Model/TransactionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Model;

/**
* Factory for creating transaction objects
*/
public class TransactionFactory {

/**
* Create purchase transaction
*/
public static Transaction createPurchase(Share share, int week) {
return new Purchase(share, week);
}

/**
* Create sale transaction
*/
public static Transaction createSale(Share share, int week) {
return new Sale(share, week);
}

}

0 comments on commit dcd5041

Please sign in to comment.