60 likes | 187 Vues
This presentation by Dr. Mark L. Hornick explores key software engineering concepts: cohesion and coupling. It examines how focused class responsibilities enhance cohesion, promoting single-task functionalities for high cohesion, while highlighting the drawbacks of low cohesion. Coupling is discussed in the context of class interdependencies, where high coupling indicates that changes in one class can affect others—an undesirable trait. The session also covers implementing strategy patterns and adapting behaviors at runtime. Engage with lab exercises on strategy and factory patterns for practical understanding.
E N D
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
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
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
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
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
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