Presentation is loading. Please wait.

Presentation is loading. Please wait.

WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.

Similar presentations


Presentation on theme: "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."— Presentation transcript:

1 WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 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.

2 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

3 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]

4 What Makes a Good Component.
To Tighten or Loosen: What Makes a Good Component. Coupling Cohesion

5 What Makes a Good Component.
To Tighten or Loosen: What Makes a Good Component. Coupling Cohesion

6 Coupling

7 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

8 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 ?

9 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 ?

10 Coupling Component A Component B

11 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

12 Reduce coupling

13 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

14

15 cohesion

16 Does one thing and does it all
cohesion Does one thing and does it all Component A Component B Component C

17 Does one thing and does it all
cohesion Does one thing and does it all Window 1 Component A Window 2 Window 3

18 Does one thing and does it all
cohesion Does one thing and does it all Component A Component B Component C

19 Does one thing and does it all
cohesion Does one thing and does it all Component A Component B Component C

20 Does one thing and does it all
cohesion Does one thing and does it all Component A Component B Component C

21 Does one thing and does it all
cohesion Does one thing and does it all Component A Component B Component C Increase cohesion

22 Does one thing and does it all
cohesion Does one thing and does it all Component A Component B Component C Increase cohesion

23 Good Component design Reduce coupling Increase cohesion Parser Logic
The chef takes care of all things related to cooking  cohesion

24 Reduce coupling Increase cohesion

25 Use these two concepts to analyze/justify design decisions.

26 Which is the better design and why?
Logic Minefield Storage Logic Minefield Storage

27 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’

28 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)

29 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

30 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

31 S O L I D Single Responsibility Principle Open-Closed Principle
Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle

32


Download ppt "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."

Similar presentations


Ads by Google