12417 soen 6461 89 high cohesion giving

This preview shows page 89 - 100 out of 121 pages.

1/24/17SOEN 646189
High CohesionGiving responsibility to Salesupports higher cohesion in Post, as well as low coupling. :POST:Sale:PaymentmakePayment()1: makePayment()1.1. create()1/24/17SOEN 646190
ControllerProblem:To assign responsibility for handling a system event?Solution:If a program receive events from external sources other than its graphical interface, add an event class to decouple the event source(s) from the objects that actually handle the events.1/24/17SOEN 646191
The Controller pattern provides guidance for generally acceptable choices. Assign the responsibility for handling a system event message to a class representing one of these choices:1. The business or overall organization (a façade controller).2. The overall "system" (a façade controller).3. An animate thing in the domain that would perform the work (a role controller).4. An artificial class (Pure Fabrication representing the use (a use case controller).1/24/17SOEN 646192
Benefits:Increased potential for reuse. Using a controller object keeps external event sources and internal event handlers independent of each other’s type and behaviour.Reason about the states of the use case. Ensure that the system operations occurs in legal sequence, or to be able to reason about the current state of activity and operations within the use case.1/24/17SOEN 646193
Controller : Example94System events in Buy Items use caseenterItem()endSale()makePayment()who has the responsibility for enterItem()?
Controller : ExampleBy controller, we have 4 choicesthe overall system Postthe overall businessStoresomeone in the real world who is active in the taskCashieran artificial handler of all systemevents of a use case BuyItemsHandler:POSTenterItem(upc, quantity):StoreenterItem(upc, quantity):CashierenterItem(upc, quantity):BuyItemsHandlerenterItem(upc, quantity)The choice of which one to use will be influenced by other factors such as cohesion and coupling1/24/17SOEN 646195
Bad design – presentation layer coupled to problem domain1/24/17SOEN 646196Object StoreEnter ItemEnd SaleUPCMake PaymentTotalQuantityTenderedBalanceCashier:POSTCommandpresses buttononEnterItem():Sale1: makeLineItem(upc, qty)Presentation Layer(Command object)Domain LayerIt is undesirable for a presentationlayer objects such as a Java applet toget involved in deciding how to handledomain processes.Business logic is embedded in thepresentation layer, which is not useful.POSTApplet should notsend this message.
Good design- presentation layer decoupled from problem domain1/24/17SOEN 646197Object StoreEnter ItemEnd SaleUPCMake PaymentTotalQuantityTenderedBalance:POSTCashier:POSTCommandpresses buttononEnterItem()1: enterItem(upc, qty):Sale1.1: makeLineItem(upc, qty)Presentation Layer(Command Object)Domain Layersystem event messagecontroller
ControllerUsing a controller object keeps external event sources and internal event handlers independent of each other’ type and behaviourThe controller objects can become highly coupled and uncohesive with more responsiblities1/24/17SOEN 646198
PolymorphismProblem:To handle alternatives based on types?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture