Evolutionary Design Solid
-
Upload
xebia-it-architects -
Category
Technology
-
view
1.152 -
download
2
description
Transcript of Evolutionary Design Solid
![Page 1: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/1.jpg)
Agile Evolutionary Design & SOLID Principles
![Page 2: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/2.jpg)
Introduction
● Typical Design Process● Agile Design Process● SOLID principles● And coding time :)● Questions anytime.
![Page 3: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/3.jpg)
Typical Evolution of System
Dream system designed to perfection and beauty. Meaning of beauty and perfection are subjective. What does it mean for you?
![Page 4: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/4.jpg)
Typical Evolution of System
Adding features
![Page 5: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/5.jpg)
Typical Evolution of System
Changing features
![Page 6: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/6.jpg)
Birth of Legacy System
Somewhere in near future
![Page 7: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/7.jpg)
Agile Design Process
![Page 8: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/8.jpg)
Beautiful System
Beautiful System
![Page 9: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/9.jpg)
Adding a feature
![Page 10: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/10.jpg)
Clean the mess
We will see some of the techniques which will help us tokeep the system clean in this presentation.
![Page 11: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/11.jpg)
After a period of time
Beautiful System.
![Page 12: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/12.jpg)
What is Agile Design?
● Not doing things upfront like having an interface for every class we write (speculative generalization) or writing a system to dynamically load the components.
● Not doing an anticipatory design
● But still setting a stage for design to evolve for tomorrow
But what helps to set the stage?
![Page 13: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/13.jpg)
XP Practices
![Page 14: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/14.jpg)
But at code level what helps to create simple and evolutionary design?
![Page 15: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/15.jpg)
Sample Application – Reporting AppConcentrate on the principles and not on the app
Reporter App
File
Read the flat file and generate the report
Reporter App
● WriteReport● ReadFile● FormatReport
![Page 16: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/16.jpg)
SOLID Principles
![Page 17: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/17.jpg)
SOLID Principles
● Single Responsibility Principle● Open Closed Principle● Liskov Substitution Principle● Interface Segregation Principle● Dependency Inversion Principle
![Page 18: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/18.jpg)
Single Responsibility Principle
![Page 19: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/19.jpg)
Single Responsibility Principle
● A class should have one, and only one, reason to change.
● Or a class should not handle more than one responsibility
● Design smell – Class changed when unrelated responsibilities change. High afferent coupling? Or multiple classes changed when a responsibility changes. High Efferent Coupling?
● Shotgun surgery and divergent change
● If it is not possible to separate the responsibilities at least show the presence of multiple roles played by the object.
● Applies not just for classes but also for modules, functions as well
● Better cohesion, encapsulation and less coupled design
![Page 20: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/20.jpg)
Better design applying SRP
Reporter App
File Reader
Report Formatter
CSV File JSON File
Requirement Changes
● Support for more file formats● May be will add more report formats (Graphical etc..)
![Page 21: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/21.jpg)
Open Closed Principle
![Page 22: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/22.jpg)
Open Closed Principle
● You should be able to extend software entities (Classes, Modules, Functions, etc.), without modifying them.
● Design smell - Change ripples through code base.
● Abstraction and polymorphism are the key.
● Chain of responsibility, Strategy pattern, Aspects...
● Separate creation from usage of objects.
● No module is 100% closed (Open/Closed/Open principle)
● Easy to lead to anticipatory design. Better to burn finger at least once.
● Service and framework interface follow OCP. Open for extension, closed for modification
![Page 23: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/23.jpg)
Better design applying OCP
File Reader
CSV File JSON File
File Reader Service
Reporter App(UI + Formatter)
![Page 24: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/24.jpg)
Liskov Substitution Principle
![Page 25: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/25.jpg)
Liskov Substitution Principle
Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T.
![Page 26: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/26.jpg)
Liskov Substitution Principle
● Functions that use references to base classes must be able to use objects of derived classes without knowing it.
● Used when inheritance was a main form of reuse.
● Design smell – Type checking in client code and changing the behavior for a specific type in client.
● Due to forcing an unrelated object into an inheritance hierarchy
● Prefer composition over inheritance whenever possible
![Page 27: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/27.jpg)
LSP Violation
File Reader
CSV File JSON File
File Reader Service Reporter (UI + Formatter)Database
New Requirement - Adding Database as a data source for report data.Adding it to File Reader Service as it is conveniently there
![Page 28: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/28.jpg)
Better design confirming to LSP
File Reader
CSV File JSON File
File Reader Service
Reporter (UI + Formatter)Database Database Reader Service
Keep Database separate as it doesn't fit in File Reader Service
![Page 29: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/29.jpg)
Interface Segregation Principle
![Page 30: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/30.jpg)
Interface Segregation Principle
● Clients should not be forced to depend on interface they don't use.
● Make fine grained interfaces that are client specific or clients should not be forced to implement interfaces they don't need
● Design smell – NotImplementException thrown for some methods (which are really not needed by the client)
● Flat and non cohesive interface problem - SRP?
● Role based interface design – Intent Revealing Interfaces by Udi Dahan (IExtractReportData)
![Page 31: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/31.jpg)
ISP Violation
![Page 32: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/32.jpg)
Better design confirming to ISP
● WriteReport● ReadFile● FormatReport
ReporterReporter
FormatReport
Report Formatter
WriteReport
Report Writer
GetData
FileReaderService
GetData
DatabaseReaderServiceInitial Interface
Current Interface
![Page 33: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/33.jpg)
Dependency Inversion Principle
![Page 34: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/34.jpg)
Dependency Inversion Principle
● 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
● Design smell – Unable to change the choice of implementation & code untestable in isolation
● Classic - Code for an interface not for an implementation
● DI frameworks to the rescue if object graph is complex
● Less coupled design
![Page 35: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/35.jpg)
DIP Violation
Text Report Formatter
Reporting App
CSV File Reader
JSON File Reader
Stuck with CSV File Reader andText Report Formatter implementations !!!
Arrows are Dependency
![Page 36: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/36.jpg)
Fixing for DIP
Text Report Formatter
Reporting App
CSV Data Extractor
JSON Data Extractor
IFormatReport
IExtractReportData
![Page 37: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/37.jpg)
Design confirming to DIP
IExtractReportData
CSV Data Extractor
JSON Data Extractor
Data Extractor Service Reporter WriterDatabase Reader Service
XML Data Extractor
Reporting Application
Report Data
![Page 38: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/38.jpg)
Credits
● SOLID Motivational Posters, by Derick Bailey, is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
● Uncle Bob for consolidation of these principles and his books Agile Software Development: Principles, Practices and Patterns and Clean Code
● Presentation is under Creative Commons Attribution-Share Alike 2.5 India License
![Page 39: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/39.jpg)
About Me
● Developer in Test at Thoughtworks
● Interested in OO, DDD, Functional Programming languages, Agile, Lean, TDD, Mocks, Automated Testing, ATDD.....
● Author and maintainer of ChromeWatir and FireDriver
● Places to find me -
● http://developer-in-test.blogspot.com● http://twitter.com/sai_venkat● http://github.com/saivenkat
![Page 40: Evolutionary Design Solid](https://reader034.fdocuments.us/reader034/viewer/2022052618/554f67bfb4c905bb178b4bdc/html5/thumbnails/40.jpg)
Thank you