Open goqp opened 6 years ago
Can't we just use something abstract like IEnumerable
from C#
, which is kinda Sequence
or Iterable
, so there is NO more abstract way to represent an iterable sequence of elements. Will it be a tight coupling?
Another idea, which I've found really useful is kinda Builder
pattern (sorry for er thing): we create inner class that allows us to build an account.
For example:
public class BasicAccount implements Account
{
public class Builder
{
private List<Transaction> transactions = new ArrayList<Transaction>();
public Builder with( Transaction t ) { this.transactions.add( t ); return this; }
Account account( User user, string currency ) { return new BasicAccount( user, currency, transactions ); }
}
private BasicAccount( User user, string currency, List<Transaction> transactions ) { ... }
}
This List<Transaction>
can now be treated as encapsulated, because noone knows about it. Building will be like this:
var account = new BasicAccount.Builder()
.with( new SomeTransaction() )
.with( new AnotherTransaction() )
.account( new BasicUser(), "USD" );
Yea thats the right concept but the builder should be disguised as a decorator! So this way we can treat it as a unity, a single concept.
new DummyAccount( new Account() );
Currently, when an account is initialized to represent an existing real-world account, the transactions from that real account must be instantiated and added to the new account object. The current interface for Account provides for the injection of a collection containing the transactions. This is tight coupling that should be avoided. A possible solution is to decorate the Account with a shell that adds each transaction object to the Account by calling the appropriate method (e.g. "apply").