1 / 20

TK2023 Object-Oriented Software Engineering

TK2023 Object-Oriented Software Engineering. CHAPTER 13b GRASP Patterns: Information Expert. INTRODUCTION. During object design, decisions are made regarding the assignment of responsibilities to software classes.

curry
Télécharger la présentation

TK2023 Object-Oriented Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TK2023 Object-Oriented Software Engineering CHAPTER 13b GRASP Patterns: Information Expert

  2. INTRODUCTION • During object design, decisions are made regarding the assignment of responsibilities to software classes. • Correct decisions will lead to systems which tend to be easier to understand, maintain and extend. Their components tend to be reusable for future applications.

  3. GRASP PATTERNS: INFORMATION EXPERT Problem What is a general principle of assigning responsibilities to objects? Solution Assign a responsibility to the information expert – the class that has the information necessary to fulfill the responsibility.

  4. EXAMPLE OF APPLICATION • In the POS application, when the Cashier has entered all items bought by the Customer, the System displays the grand total of the current sale. So, Who should be responsible for knowing the grand total of a sale? • Using the Information Expert pattern, we should be looking for the class of objects that has the information needed to determine the total.

  5. Do we look in the Domain Model or the Design Model? • If there are relevant classes in the Design Model, look there first. • Otherwise, look in the Domain Model. Attempt to use (or expand) its representations to inspire the creation of corresponding design classes.

  6. For this example, let’s assume that our Design Model is minimal. So, we look in the Domain Model. What information do we need to determine the grand total? We need to know about all the SalesLineItem instances of a sale and the sum of their subtotals.

  7. According to the Information Expert pattern, Sale is suitable for that responsibility.

  8. We introduce an operation called getTotal() through which a Sale object will carry out the responsibility. t = getTotal : Sale Sale time ... getTotal ()

  9. For a Sale object to calculate the grand total, it needs the subtotal for each line item. Who should be responsible for knowing the subtotal of a line item? What information is required to determine the line item subtotal? i. quantity ii. price

  10. Sale time 1 Contains * 1 .. Product Sales Description * 1 LineItem Described - by description quantity price itemID • Using the Information Expert pattern (and referring to the Domain Model), SalesLineItem could be given that responsibility.

  11. t = getTotal 1 *: st = getSubtotal lineItems [ i ] : : Sale SalesLineItem • We introduce an operation called getSubtotal() through which a SalesLineItem object will carry out the responsibility.

  12. Sale time ... () getTotal SalesLineItem quantity () getSubtotal

  13. For a SalesLineItem object to calculate its subtotal, it needs the price of the item. Who should be responsible for knowing the price of an item? The ProductDescription object has the information for carrying out the responsibility. So, by the Information Expert pattern, that object is the information expert for that responsibility.

  14. 1 *: st = getSubtotal t = getTotal lineItems [ i ] : : Sale SalesLineItem 1 . 1 : p = getPrice : Product Description • We introduce an operation called getPrice() through which a ProductDescription object will carry out the responsibility.

  15. Sale time ... getTotal () Product Description SalesLineItem description quantity price itemID getSubtotal () () getPrice

  16. In conclusion, to fulfill the responsibility of knowing and answering the total of a sale, we assigned three responsibilities to three design classes of objects as follows:

  17. DISCUSSION • Information Expert is frequently used in the assignment of responsibilities; it is a basic guiding principle used continuously in object design. • Expert usually leads to designs where a software object does those operations that are normally not done to the inanimate real-world thing it represents.

  18. Note that the fulfillment of a responsibility often requires information that is spread across different classes of objects. This leads to objects interacting via messages to share the work. • Real-world analogy: We commonly give responsibility to individuals who have the information / resources necessary to fulfill a task.

  19. CONTRAINDICATIONS • In some situations, a solution suggested by Information Expert is undesirable, usually because of problems in coupling and cohesion. Example: Who should be responsible for saving a Sale in a database?

  20. BENEFITS • Information encapsulation is maintained since objects use their own information to fulfill tasks. This usually supports low coupling, which leads to more robust and maintainable systems. • Behaviour is distributed across the classes that have the required information, thus encouraging more cohesive class definitions that are easier to understand and maintain.

More Related