110 likes | 212 Views
Session 33 More on SOLID. Steve Chenoweth Office: Moench Room F220 Phone: (812) 877-8974 Email: chenowet@rose-hulman.edu. Chandan Rupakheti Office: Moench Room F203 Phone: (812) 877-8390 Email: rupakhet@rose-hulman.edu. Today. The SOLID coding exercises
E N D
Session 33 More on SOLID Steve Chenoweth Office: Moench Room F220 Phone: (812) 877-8974Email: chenowet@rose-hulman.edu ChandanRupakheti Office: Moench Room F203 Phone: (812) 877-8390Email: rupakhet@rose-hulman.edu
Today • The SOLID coding exercises • See course website for zip file of all 5 of these • They go with the quiz to turn in before class (as usual) • Bring along your answers to discuss in class, too
Recall what SOLID is: S - SRP: Single Responsibility Principle • We discussed this one in Session 13 O - OCP: Open Closed Principle L - LSP: Liskov Substitution Principle I - ISP: Interface Segregation Principle D - DIP: Dependency Inversion Principle Pioneered by Robert Martin (Uncle Bob)
Recall SRP THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE. (You looked at Pablo’s eBook on this – see especially pp. 15-25)
OCP SOFTWARE ENTITIES (CLASSES, MODULES, FUNCTIONS, ETC.) SHOULD BE OPEN FOR EXTENSION BUT CLOSED FOR MODIFICATION.
LSP FUNCTIONS THAT USE REFERENCES TO BASE CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT.
ISP CLIENTS SHOULD NOT BE FORCED TO DEPEND UPON INTERFACES THAT THEY DO NOT USE .
DIP A. HIGH LEVEL MODULES SHOULD NOT DEPEND UPON LOW LEVEL MODULES. BOTH SHOULD DEPEND UPON ABSTRACTIONS. B. ABSTRACTIONS SHOULD NOT DEPEND UPON DETAILS. DETAILS SHOULD DEPEND UPON ABSTRACTIONS
More Info • Look at the SOLID article we saw before. There’s more in there beyond SRP! • The SRP part you already studied is thru p 26. • Then there’s an article on each of the other SOLID principles, too.
Let’s Learn By Doing! Download SolidExamples (a zip file of 5 Java examples) from the course website. The quiz asks describe where there are issues, with which of the SOLID principles. And – How you would fix them! Do the quiz before class, as usual, but also be ready to discuss your answers in class.
A “Solid” Summary • SRP: THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE. • OCP: SOFTWARE ENTITIES SHOULD BE OPEN FOR EXTENSION BUT CLOSED FOR MODIFICATION • LSP: FUNCTIONS THAT USE REFERENCES TO BASE CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT. • ISP: CLIENTS SHOULD NOT BE FORCED TO DEPEND UPON INTERFACES THAT THEY DO NOT USE . • DIP: • HIGH LEVEL MODULES SHOULD NOT DEPEND UPON LOW LEVEL MODULES. BOTH SHOULD DEPEND UPON ABSTRACTIONS. • ABSTRACTIONS SHOULD NOT DEPEND UPON DETAILS. DETAILS SHOULD DEPEND UPON ABSTRACTIONS