It is more a matter of architecture / best practice than anything else, so please feel free to add your two cents. I know that I indicated the status in the title, but this applies to any basic property of the object. I think the example account below will help demonstrate my question a little better than status.
Here is an example Account object:
public class Account { private IList<Transaction> _transactions; public AddTransaction(trans as Transaction) { _transaction.add(trans) } }
Now let's say that I want to start logging every time a transaction is added with this object.
public class AccountHistory { private DateTime _historyDate; private String _details; public AccountHistory(string details) { _historyDate = DateTime.Now; _details = details; } }
At this level, what I would normally do is add a collection of history events to the account object, and also add a line of code to create a history event inside the AddTransaction () method like this
public AddTransaction(trans as Transaction) { _transaction.add(trans); **_historyEvents.add(new AccountHistory("Transaction Added: " + trans.ToString());** }
Now in the next part there is a problem. Suppose I want to make a bulk posting, and I want to keep a record of which accounts were changed in this bulk posting for something like a report, or if I needed to cancel it later. Therefore, I would create such an object.
public class HistoryGroup() { private IList<AccountHistory> _events; }
Here I see several different parameters for handling this, since it cannot be handled by the above example.
1) Create a function in the object of the service type, which iterates over the list of accounts that call the AddTransaction () method, and also creates history records associated with the HistoryGroup
public void AddTransactions(IList<Account> accounts, Transaction trans) { HistoryGroup history = new HistoryGroup(); for (int x=0;x <=accounts.Count - 1; x++) { accounts(x).AddTransaction(trans); history.AddEvent(new AccountHistory("Added Transaction: " + trans.ToString(); } }
2) Pass some type of HistoryManager object to the AddTransaction method along with the transaction to be added. The function can then use the history manager to create entries.
Ok, this post is long enough. If I was not clear enough, let me know. Thanks for your input.