2008 Exam answers

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(Question 1)
Line 2: Line 2:
 
Possible improvements to the design:
 
Possible improvements to the design:
 
* Replace the Pair class with a Transaction class and two subclasses CreditTransaction and DebitTransaction.  These classes will contain the information that was contained in Pair, and any other behavior related to transactions which is likely to have leaked out into the rest of the system.
 
* Replace the Pair class with a Transaction class and two subclasses CreditTransaction and DebitTransaction.  These classes will contain the information that was contained in Pair, and any other behavior related to transactions which is likely to have leaked out into the rest of the system.
*Currently, the Pair class is used to keep track of the Stock a Stockholder owns (price and date of purchase or sale) and to record transactions (the stock that was traded and the date of the trade).
+
**Currently, the Pair class is used to keep track of the Stock a Stockholder owns (price and date of purchase or sale) and to record transactions (the stock that was traded and the date of the trade).
*'''Violations:'''   
+
**'''Violations:'''   
**[[Behavioral completeness]] - The Pair class currently only acts as a data container but does not contain the behaviour related to that data.
+
***[[Behavioral completeness]] - The Pair class currently only acts as a data container but does not contain the behaviour related to that data.
**[[One key abstraction]] - Pair currently does not capture one particular domain concept but tries to do several things at once. This is also related to [[Single responsibility principle]].
+
***[[One key abstraction]] - Pair currently does not capture one particular domain concept but tries to do several things at once. This is also related to [[Single responsibility principle]].
**[[Separation of concerns]] - Pair should only have one particular responsibility but at the moment fulfills several. These should be separated.
+
***[[Separation of concerns]] - Pair should only have one particular responsibility but at the moment fulfills several. These should be separated.
 
* Replace Stock class with CompanyStock and OwnedStock.  These classes will not share a common super class as they differ greatly in what they represent.
 
* Replace Stock class with CompanyStock and OwnedStock.  These classes will not share a common super class as they differ greatly in what they represent.
* The Stock class currently tries to represent both a single share (OwnedStock) and the master share with information about the stock for a particular company (CompanyStock).
+
** The Stock class currently tries to represent both a single share (OwnedStock) and the master share with information about the stock for a particular company (CompanyStock).
*'''Violations:'''  
+
**'''Violations:'''  
**[[Single responsibility principle]] - The Stock class tries to represent two very different concepts at the same time.  
+
***[[Single responsibility principle]] - The Stock class tries to represent two very different concepts at the same time.  
**[[One key abstraction]]
+
***[[One key abstraction]]
 
* Broker and StockHolder should both hold a reference to an Account object.  This would replace the brokersAccount property of Broker.  The Account class would manage Transactions and include a reference to the account holder (Broker or StockHolder).
 
* Broker and StockHolder should both hold a reference to an Account object.  This would replace the brokersAccount property of Broker.  The Account class would manage Transactions and include a reference to the account holder (Broker or StockHolder).
 
**'''Violations:'''  [[Single responsibility principle]]
 
**'''Violations:'''  [[Single responsibility principle]]
Line 17: Line 17:
 
**'''Violations:'''  [[Single responsibility principle]]
 
**'''Violations:'''  [[Single responsibility principle]]
 
* Once the notion of a person (Stockholder) and an account has been separated, all the accounts for one particular person can be stored as a Set by the object representing the person.  
 
* Once the notion of a person (Stockholder) and an account has been separated, all the accounts for one particular person can be stored as a Set by the object representing the person.  
* At the moment, accounts are chained together through the next link in the StockHolder class. This further shows that two different concepts have been muddled up. This also means that redundant data will be stored since for each account the data for the person is stored separately, rather than that data being stored only once.
+
** At the moment, accounts are chained together through the next link in the StockHolder class. This further shows that two different concepts have been muddled up. This also means that redundant data will be stored since for each account the data for the person is stored separately, rather than that data being stored only once.
 +
**'''Violations:''' 
 +
***[[Single responsibility principle]]
 +
***[[Separation of concerns]]
 +
***[[One key abstraction]]

Revision as of 04:26, 17 July 2009

Question 1

Possible improvements to the design:

  • Replace the Pair class with a Transaction class and two subclasses CreditTransaction and DebitTransaction. These classes will contain the information that was contained in Pair, and any other behavior related to transactions which is likely to have leaked out into the rest of the system.
    • Currently, the Pair class is used to keep track of the Stock a Stockholder owns (price and date of purchase or sale) and to record transactions (the stock that was traded and the date of the trade).
    • Violations:
  • Replace Stock class with CompanyStock and OwnedStock. These classes will not share a common super class as they differ greatly in what they represent.
    • The Stock class currently tries to represent both a single share (OwnedStock) and the master share with information about the stock for a particular company (CompanyStock).
    • Violations:
  • Broker and StockHolder should both hold a reference to an Account object. This would replace the brokersAccount property of Broker. The Account class would manage Transactions and include a reference to the account holder (Broker or StockHolder).
  • Broker and StockHolder should both hold a reference to ContactDetails object. Alternatively they could both inherit from a Person class, but if we favor composition over inheritance this would seem the less preferred solution. This also wouldn't be a good solution if a Broker can be a company as well as a person. This would allow personal details of Brokers and StockHolders to be stored. In the current design the notion of a Person is mixed with that of an Account. The improved design separates these two and would allow someone to have multiple accounts.
  • Once the notion of a person (Stockholder) and an account has been separated, all the accounts for one particular person can be stored as a Set by the object representing the person.
    • At the moment, accounts are chained together through the next link in the StockHolder class. This further shows that two different concepts have been muddled up. This also means that redundant data will be stored since for each account the data for the person is stored separately, rather than that data being stored only once.
    • Violations:
Personal tools