1 / 6

More on Strategy

More on Strategy. Cohesion vs. Coupling Implementing the Strategy Pattern Changing strategies (behaviors) at runtime. Cohesion: How focused the responsibilities of a class are. Cohesion : Does a class do many unrelated things? If “yes”, then it has low cohesion (bad)

shanna
Download Presentation

More on Strategy

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. More on Strategy • Cohesion vs. Coupling • Implementing the Strategy Pattern • Changing strategies (behaviors) at runtime SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder

  2. Cohesion: How focused the responsibilities of a class are Cohesion: Does a class do many unrelated things? If “yes”, then it has low cohesion (bad) Does a class represent only one thing? If “yes”, then it has high cohesion (good) • Some of our definitions of cohesion from last time: • Few behaviors in a class • Each class should have one focus SE-2811 Dr. Mark L. Hornick

  3. Coupling: How closely two or more classes are related Does changing code in one class require changes in another class?? • If “yes”, then it has high coupling (bad) • Changing swim or quack behaviors does not require changes to the Duck class (low coupling) SE-2811 Dr. Mark L. Hornick

  4. Week 2, Day 1 • Cohesion vs. Inheritance • Implementing the Strategy Pattern • (?) Changing strategy at run-time Tomorrow: • Factory Pattern Lab: • Use Strategy & Factory Patterns (See online) SE-2811 Dr. Mark L. Hornick

  5. Q1 • A Duck class that swims, quacks, and displays itself exhibits (pick the best choice) • Low cohesion • High cohesion • Low coupling • High coupling SE-2811 Dr. Mark L. Hornick

  6. Q2 • Mallard, Redhead, Decoy, and Mute duck classes that each implement similar quacking methods exhibit (pick the best choice) • Low cohesion • High cohesion • Low coupling • High coupling SE-2811 Dr. Mark L. Hornick

More Related