WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010. They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here. These slides contain a lot of animations. For optimal results, watch in slideshow mode.
Which is the better Minesweeper design and why? Logic Minefield Storage Logic Minefield Storage :Logic m:Minefield :Storage :Logic m:Minefield :Storage mark mark mark mark update(m) update(m) get info get info
CS2103/T, Lecture 7, Part 1, [Oct 2, 2015] To Tighten or Loosen: What Makes a Good Component. CS2103/T, Lecture 7, Part 1, [Oct 2, 2015]
What Makes a Good Component. To Tighten or Loosen: What Makes a Good Component. Coupling Cohesion
What Makes a Good Component. To Tighten or Loosen: What Makes a Good Component. Coupling Cohesion
Coupling
If I change B , will it require a change in A ? NO WAY It might Dependency == Coupling (Class/method/…) Component A Component B If I change B , will it require a change in A ? NO WAY It might
If I change B , will it require a change in A ? Coupling Component A Component B If I change B , will it require a change in A ?
If I change B , will it require a change in A ? Coupling Component A Component B If I change B , will it require a change in A ?
Coupling Component A Component B
If I change B, will it require a change in A? Yes, It might Component A Component B If I change B, will it require a change in A? Yes, It might Reduce coupling
Reduce coupling
Good Component design Reduce coupling cohesion Parser Logic Unnecessary coupling example: Chef keeps his/her cash in the cash register? Does Parser has any business being coupled to Logic? cohesion
cohesion
Does one thing and does it all cohesion Does one thing and does it all Component A Component B Component C
Does one thing and does it all cohesion Does one thing and does it all Window 1 Component A Window 2 Window 3
Does one thing and does it all cohesion Does one thing and does it all Component A Component B Component C
Does one thing and does it all cohesion Does one thing and does it all Component A Component B Component C
Does one thing and does it all cohesion Does one thing and does it all Component A Component B Component C
Does one thing and does it all cohesion Does one thing and does it all Component A Component B Component C Increase cohesion
Does one thing and does it all cohesion Does one thing and does it all Component A Component B Component C Increase cohesion
Good Component design Reduce coupling Increase cohesion Parser Logic The chef takes care of all things related to cooking cohesion
Reduce coupling Increase cohesion
Use these two concepts to analyze/justify design decisions.
Which is the better design and why? Logic Minefield Storage Logic Minefield Storage
Which is the better design and why? Logic Minefield Storage Logic Minefield Storage Refer to Coupling and Cohesion when analyzing designs How does this application of SRP change C & C? TextUi Formatter Use the right terms, give a sensible explanation, including assumptions, instead of ‘b looks messy’ or ‘a is prettier’
Dependency Inversion Principle High-level class coupled to low-level class Low-level class coupled to high-level class Logic Minefield Logic Minefield Logic {abstract} Field Minefield Logic <<interface>> Field Minefield Dependency Inversion Principle High-level modules should not depend on low-level modules. Both should depend on abstractions (should sometimes, preferred not to)
Dependency Inversion Principle High-level class coupled to low-level class Logic Minefield Farmfield Logic <<interface>> Field Minefield Dependency Inversion Principle High-level modules should not depend on low-level modules. Both should depend on abstractions
Open-Closed Principle A class should be open for extensions but closed for modifications {abstract} Timer FixedTimer Random Timer Farmfield Main Logic <<interface>> Field Minefield Chess Main Chessboard SinglePlayer Logic SP Main
S O L I D Single Responsibility Principle Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle