1 / 8

Week 4, Day 3 Observer, continued

Week 4, Day 3 Observer, continued. Return Quiz Coupling & Cohesion Observers Class structure for observers Sequence diagram for observers How it improves coupling How it improves cohesion Downsides Exam next week (Week 5), Tuesday. Coupling vs. Cohesion.

halen
Download Presentation

Week 4, Day 3 Observer, continued

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. Week 4, Day 3Observer, continued • Return Quiz • Coupling & Cohesion • Observers • Class structure for observers • Sequence diagram for observers • How it improves coupling • How it improves cohesion • Downsides • Exam next week (Week 5), Tuesday SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder

  2. Coupling vs. Cohesion • Module 4 shows what we are trying to avoid: low cohesion and high coupling (more lines==lower) (more lines==higher) SE-2811 Dr. Mark L. Hornick http://www.jesusgilhernandez.com/2012/11/28/cohesion-and-coupling/

  3. Basic class relationships Subject ------------------------------ attach():voiddetach():voidnotifyObservers():void Observer---------------- update(???):void -observers 1..* SubjectClass ObserverClass1 ObserverClass2

  4. Collaborations between objects in the Observer pattern s:SubjectClass o1:ObserverClass1 o2:ObserverClass2 attach(???) attach(???) notifyObservers() update(???) getContextSpecificInfo() update(???) getContextSpecificInfo()

  5. Consequences (positive) Coupling between Subject and Observers: • Subject knows it has a list of Observers, but not specific classes • Each Observer conforms to the simple interface of the abstract Observer Interface. • Hence, coupling is • Minimal • Abstract

  6. Consequences (positive) Cohesion is increased from single-class implementation • State management and display/response are separated • E.g. GUI innards separated from “your code” • E.g. Web access separated from display

  7. Consequences (negative) • Broadcast communication • Notification is broadcast to all interested objects. • Observers can be added/removed at any time. • Observer decides when it needs to be notified. • Unexpected updates • Observers have no knowledge • Of each other’s presence. • About the cost of “state change of subject” • Cascade of updates. SE-2811 Dr. Mark L. Hornick

  8. [ADDED SLIDE]Timing of multiple observers • All observers get notified at essentially the same time. • In the lab, all observers should be integrated into the same program and run at the same time. SE-2811 Dr. Mark L. Hornick

More Related