SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
SOLID Software-Engineering Principles
- A must know for developers -
Roland Petrasch
5th
SET Meet-up
Jan. 6, 2016
Bangkok, Thailand
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
2 / 36
SET — Software Engineering Thailand
The Interest Group from & (not only) for Developers
Open Group: Members, Sponsors and Organizers welcome
Next topics: S.O.L.I.D., VR Game Design with Unity, IoT Show
Case, Eye Tracking, SE Start-ups: Lessons Learned
Contact
Roland Petrasch
Thammasat University, Department of Computer Science,
Rangsit Campus, Pathum Thani
roland.petrasch@cs.tu.ac.th
roland.petrasch@gmail.com
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
3 / 36
SOLID
Software-Engineering Principles
Agenda
A few Basics, e.g. dependency, coupling, cohesion
S.O.L.I.D. Software-Engineering Principles
SRP: Responsibilities and OO → OCP
Inheritance and Liskov
Substitution Principle
Modules, components &
Interface Segregation
Dependency (Abstraction &) Inversion
Discussion
S O L I D
R C S S I
P P P P P
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
4 / 36
SOLID Basics
Modules & components
Module → OO: class(es) + interface(s)
Component = module(s), package, service
Provider → client, interface(s)
Encapsulation / information hiding
Can be OO (instantiation) or non-OO
Dependency
Interdependence between software modules
Strong, e.g. inheritance, content
Weak, e.g. message passing, parameters
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
5 / 36
SOLID Basics
Coupling
Inter-module aspect: Degree of (in)direct
dependencies to other components / modules
Example
Tight coupling: Component uses implementation
Loose coupling: Component uses an abstraction
OO: Inheritance
Loose coupling is better than
tight coupling … normally
Source: [4] Rodriguez et al., 2001
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
6 / 36
SOLID Basics
Coupling
Example
Surveillance App
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
7 / 36
SOLID Basics
Cohesion
Intra-module aspect: Degree to which the elements
of a module belong together
Behavior and attributes of a module should “work
together” (calsule), i.e. the functions/method a class
must use the attributes → high cohesion
Otherwise functions/method and attributes do not
belong together → low cohesion
High cohesion is good,
low cohesion is bad … normally
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
8 / 36
SOLID Basics
Cohesion
Example:
class Camera {
String name;
Integer fps;
Integer resolution;
Boolean motionTracking;
public String getName() {
...
}
}
class CameraController {
public String
validateSettings() {
...
if (fps >= 30 &&
resolution >= ...
}
}
Low or no cohesion
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
9 / 36
SOLID SE Principles
SOLID
Bertram Meyer described SE principles, DbC … [1]
5 Principles were introduced in 2000s by
Robert C. Martin [3]
Principles can lead to better software quality
Maintainability
Understandability / Readability
Correctness
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
10 / 36
SOLID SE Principles
SRP – Single Responsibility Principle
SRP
A class should have only one reason to change
Responsibility relates to features and aspects
Technological aspects, e.g. output device(s), persistence
Domain-oriented aspects, e.g. CRM, production, HR
Architectural aspects, e.g. cloud app, mobile client
Cohesion and coupling are important underlying
concepts for SRP
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
11 / 36
SOLID SE Principles
SRP – Single Responsibility Principle
Example: entity class and persistence
M D C C
class Camera {
String name;
Integer fps;
Integer resolution;
Boolean motionTracking;
public String getName() {
...
}
public void save() {
// some JDBC statements
...
}
}
class CameraDAO {
public void save(
Camera camera) {
...
}
}
2 reasons for
change: domain &
persistence FW
class Camera {
...
Separation of
concerns
POJO
Data
Access
Object
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
12 / 36
SOLID SE Principles
SRP – Single Responsibility Principle
DoDOO – Don't destroy Object-Orientation
M D C C
class Camera {
String name;
Integer fps;
Integer resolution;
VDOBuffer buffer;
public String getName() {
...
}
}
class CameraLogic {
public void record(
Camera camera) {
...
}
public void stream(
Camera camera,
Stream stream) {
...
}
}
OO Encapsulation: class consists of
attributes (data member) and behavior
(methods / member functions)
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
13 / 36
SOLID SE Principles
SRP – Single Responsibility Principle
DoMa – The domain matters
M D C C
class Camera {
String OEM;
String name;
Integer fps;
Integer resolution;
VDOBuffer buffer;
Location location;
IP ip;
public String getName() {
...
}
}
object Camera1:
OEM = “Yamunaki”
name = “Y28”
fps = 30
Resolution = “1 MPixel”
location = “Office”
Ip = 1.2.1.1
A camera (type) is not a camera (device)
→ 2 domain responsibilities
object Camera1:
OEM = “Yamunaki”
name = “Y28”
fps = 20
Resolution = “2 MPixel”
location = “Floor”
Ip = 1.2.1.2
Redundant data,
semantic gaps
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
14 / 36
SOLID SE Principles
SRP – Single Responsibility Principle
Use the OOA pattern „spec./product“,
“model/exemplar”, “type/object“
M D C C
class Camera {
String OEM;
String name;
Integer max_fps;
Integer max_resolution;
public String getName() {
...
}
}
class CameraDevice {
Camera camera;
Integer fps;
Integer resolution;
VDOBuffer buffer;
Location location;
IP ip;
public String record() {
...
}
1 *
Camera type / spec Camera device / exemplar
Many-to-one association.
NOT inheritance
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
15 / 36
SOLID SE Principles
OCP - Open/Closed Principle
Software entities (classes, modules, functions, etc.)
should be open for extension, but closed for
modification
Use some good 'ol design patterns, e.g.
decorator, strategy, wrapper … ?
Yes and no: DP can be useful, but
OCP goes deeper than that
Example: Camera that provides pan, tilt, and zoom
functions. Need to change the Camera class?
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
16 / 36
SOLID SE Principles
OCP - Open/Closed Principle
Camera class should be closed
to modifications → „new features“
M D C C
class Camera {
String OEM;
String name;
Integer fps;
Integer resolution;
Angle pan;
Angle tilt;
Integer zoom;
...
}
A camera should only be
changed for one reason
(core functionality /
responsibility),
not for new feature
implementation (SRP).
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
17 / 36
SOLID SE Principles
OCP - Open/Closed Principle
Camera extension … so many possibilities
Inheritance Simple Wrapper Decorator
M D C C
class Camera {
...
}
class PTZCamera
extends Camera {
...
}
class Camera {
...
}
class PTZCamera
{
Camera camera;
...
}
class
IPCamera
{
...
}
class
PTZCamera
{
Camera
camera;
...
}
interface
Camera {
record()
}
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
18 / 36
SOLID SE Principles
OCP - Open/Closed Principle
OCP focuses on class design
Strong relationship to SRP, cohesion, and coupling
Cohesion should be high when OCP is applied
Coupling cannot be avoided, but maybe minimized
Avoid over-engineering
Coupling is not always so bad as it seems,
e.g. domain / entity modeling
Using interfaces instead of implementations has
advantages, but ask yourself: Do I need this here
now or in the future?
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
19 / 36
SOLID SE Principles
Liskov Substitution Principle
Derived types must be completely
substitutable for their base types
Strong behavioral subtyping
Barbara Liskov and Jeannette Wing, 1994
Derived class can only override the methods of the
superclass when the functionality is preserved
Example:
A Person provides or “uses“ the surveillance system.
It can be the OEM, the home owner or an intruder
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
20 / 36
SOLID SE Principles
Liskov Substitution Principle
Example:
M D C C
Are we really interested in the birthday
of the thief?
An OEM probably hasn't a first-name.
Does the home owner have attributes?
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
21 / 36
SOLID SE Principles
Liskov Substitution Principle
Example: problems
OEM→getFirstName() doesn't really make sense
(OEM isn't substitutable for its base type Person)
Home owner doesn't have attributes? Really?
Intruder/Thief has unknown birthday, first-name etc.
(we'll never know)
We mixed up 2 concepts: roles and persons
Violation of SRP and Liskov substitution principle
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
22 / 36
SOLID SE Principles
Liskov Substitution Principle
Persons and Roles … so many possibilities
Inheritance Simple Role Pattern ...
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
23 / 36
SOLID SE Principles
Liskov Substitution Principle
System Analysis / OOA is not OOD
OOA: “The system identifies intruder an other
unwanted persons ...“
LSP applies to OOD, not to OOA
M D C C
OOA
OOD
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
24 / 36
SOLID SE Principles
ISP Interface Segregation Principle
ISP addresses high level architectural aspects
A client should never be forced to implement an
interface that it doesn’t use
A clients shouldn’t be forced to depend on methods
it doesn't use
Provide specific interfaces to clients (components)
Related pattern: facade pattern
Example: component interfaces to clients of the
surveillance system
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
25 / 36
SOLID SE Principles
ISP Interface Segregation Principle
Facade provides one common interface to clients
→ Clients depend on methods they don't need/use
M D C C
The monitor doesn't
need the configuration
features.
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
26 / 36
SOLID SE Principles
ISP Interface Segregation Principle
Facade interfaces are specific for clients (SRP)
M D C C
Interfaces of the
component are segregated
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
27 / 36
SOLID SE Principles
ISP Interface Segregation Principle
Camera forces clients to implement methods
they don't use
M D C C
How to implement the
CameraControl?
A control interface?
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
28 / 36
SOLID SE Principles
ISP Interface Segregation Principle
Camera interfaces
should be client-specific,
not implementation-
specific
M D C C
Interfaces for
different clients
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
29 / 36
SOLID SE Principles
DIP Dependency Inversion principle
High-level modules should not depend on low-level
modules
Both should depend on abstractions.
Abstractions should not depend upon details
Details should depend upon abstractions
Good example is the DAO pattern
Data Access (low-level) depends on abstraction
(and on technological modules = libs, FW etc.)
Entity classes (high-level) do not depend on DAO
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
30 / 36
SOLID SE Principles
DIP Dependency Inversion principle
High-level modules should not depend on low-level
modules
This is also true for inheritance, e.g.
Camera (superclass) should never „know“
a subclass PTZCamera. It would detroy the
whole hierarchie
PTZCamera depends on Camera already and
is low-level from the superclass point of view.
M D C C
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
31 / 36
SOLID SE Principles
DIP Dependency Inversion principle
Architecture: Business logic is always high-level
M D C C
BL
BL
BL
BL
BL
Controller
Controller
Controller
View
View
View
Persistence
Persistence
Persistence
Communication
Communication
VO
VO
Programming Language
S O L I D
R C S S I
P P P P P
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
32 / 36
SOLID SE Principles
DIP Dependency Inversion principle
Why it is called “inversion”? What is inverted?
High-level module need other low level modules
Example: domain objects need to be persisted,
so they depend on these features of low-level
module for persistence
This dependency (high-level module depend on
low-level modules) is inverted, so only low-level
modules depend on high-level modules,
Example: domain objects are independent of
low-level module for persistence services
M D C C
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
33 / 36
Discussion
SOLID principles are important, but
other principles and rules exist, e.g.
“No circular dependencies“ rule
Tight coupling often causes cyclic dependency
Ripple effect: small & local change → “global”
effect
Source: Agustín Ruiz (espejo)
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
34 / 36
Discussion
SOLID is good, but not a simple formula
(Principles are not just rules that can be applied)
Don't start with metrics, those numbers can be tricky
(start with a goal and ideas and principles and …)
Check acceptance for SOLID in your team
(A hot potato? Lost in Spaghetti code?
Good things need time)
Maintainability, re-use and understandability are real
cost-savers; go the extra mile for SOLID
Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles
Roland Petrasch, Thammasat University
35 / 36
SOLID
Software-Engineering Principles
References
[1] Bertrand Meyer: Object-Oriented Software Construction. Prentice Hall,
1997
[2] Erich Gamma et al.: Design Patterns: Elements of Reusable Object-
Oriented Software. Addison-Wesley, 1994
[3] Robert C. Martin: Agile Software Development, Principles, Patterns, and
Practices. Pearson, 2002
[4] Daniel Rodriguez, Rachel Harrison: An Overview of Object-Oriented
Design Metrics. RUCS/2001/TR/A, The University Of Reading, 2001
[5] Patkos Csaba: The SOLID Principles.
http://code.tutsplus.com/series/the-solid-principles--cms-634
[6] Tigerfreak: Homer Simpson
http://s450.photobucket.com/user/tigersafreak/media/homer-simpson-wal
lpaper-brain-1024-.jpg.html
SOLID Software-Engineering Principles
- A must know for developers -
Roland Petrasch
Thank you for
your attention

Weitere ähnliche Inhalte

Ähnlich wie S.O.L.I.D. Software-Engineering Principles - a must know for developers

SET Software Engineering Thailand Meeting: Functional Programming with Scala ...
SET Software Engineering Thailand Meeting: Functional Programming with Scala ...SET Software Engineering Thailand Meeting: Functional Programming with Scala ...
SET Software Engineering Thailand Meeting: Functional Programming with Scala ...Prof. Dr. Roland Petrasch
 
Hiranava Das Resume
Hiranava Das ResumeHiranava Das Resume
Hiranava Das ResumeHiranava Das
 
NUS-ISS Learning Day 2016 - Tiny Components But Big Possibilities
NUS-ISS Learning Day 2016 - Tiny Components But Big PossibilitiesNUS-ISS Learning Day 2016 - Tiny Components But Big Possibilities
NUS-ISS Learning Day 2016 - Tiny Components But Big PossibilitiesNUS-ISS
 
Sparklyr: Big Data enabler for R users
Sparklyr: Big Data enabler for R usersSparklyr: Big Data enabler for R users
Sparklyr: Big Data enabler for R usersICTeam S.p.A.
 
Sparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAM
Sparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAMSparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAM
Sparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAMData Science Milan
 
Refactoring Workflows & Techniques Presentation by Valentin Stantescu
Refactoring Workflows & Techniques Presentation by Valentin StantescuRefactoring Workflows & Techniques Presentation by Valentin Stantescu
Refactoring Workflows & Techniques Presentation by Valentin StantescuPayU Türkiye
 
Dashboards for Business Intelligence
Dashboards for Business IntelligenceDashboards for Business Intelligence
Dashboards for Business IntelligencePetteriTeikariPhD
 
"Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma...
"Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma..."Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma...
"Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma...eLiberatica
 
NEHA JAIN_RESUME
NEHA JAIN_RESUMENEHA JAIN_RESUME
NEHA JAIN_RESUMENeha Jain
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeyCefalo
 
Introduction to Enterprise Architecture and TOGAF 9.1
Introduction to Enterprise Architecture and TOGAF 9.1Introduction to Enterprise Architecture and TOGAF 9.1
Introduction to Enterprise Architecture and TOGAF 9.1iasaglobal
 
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...shohi1
 
DRESD Project Presentation - December 2006
DRESD Project Presentation - December 2006DRESD Project Presentation - December 2006
DRESD Project Presentation - December 2006santa
 
UNIT1_Himani Sharma.pptx
UNIT1_Himani Sharma.pptxUNIT1_Himani Sharma.pptx
UNIT1_Himani Sharma.pptxAman287268
 
Using a Reputation Framework to Identify Community Leaders in Ontology Engine...
Using a Reputation Framework to Identify Community Leaders in Ontology Engine...Using a Reputation Framework to Identify Community Leaders in Ontology Engine...
Using a Reputation Framework to Identify Community Leaders in Ontology Engine...Christophe Debruyne
 
CS8592_Notes_008_edubuzz360.pdf
CS8592_Notes_008_edubuzz360.pdfCS8592_Notes_008_edubuzz360.pdf
CS8592_Notes_008_edubuzz360.pdfAROCKIAJAYAIECW
 

Ähnlich wie S.O.L.I.D. Software-Engineering Principles - a must know for developers (20)

CS8592-OOAD Lecture Notes Unit-1
CS8592-OOAD Lecture Notes Unit-1CS8592-OOAD Lecture Notes Unit-1
CS8592-OOAD Lecture Notes Unit-1
 
SET Software Engineering Thailand Meeting: Functional Programming with Scala ...
SET Software Engineering Thailand Meeting: Functional Programming with Scala ...SET Software Engineering Thailand Meeting: Functional Programming with Scala ...
SET Software Engineering Thailand Meeting: Functional Programming with Scala ...
 
Hiranava Das Resume
Hiranava Das ResumeHiranava Das Resume
Hiranava Das Resume
 
PDC+++ Module 2 Class 7
PDC+++ Module 2 Class 7PDC+++ Module 2 Class 7
PDC+++ Module 2 Class 7
 
NUS-ISS Learning Day 2016 - Tiny Components But Big Possibilities
NUS-ISS Learning Day 2016 - Tiny Components But Big PossibilitiesNUS-ISS Learning Day 2016 - Tiny Components But Big Possibilities
NUS-ISS Learning Day 2016 - Tiny Components But Big Possibilities
 
Sparklyr: Big Data enabler for R users
Sparklyr: Big Data enabler for R usersSparklyr: Big Data enabler for R users
Sparklyr: Big Data enabler for R users
 
Sparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAM
Sparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAMSparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAM
Sparklyr: Big Data enabler for R users - Serena Signorelli, ICTEAM
 
Refactoring Workflows & Techniques Presentation by Valentin Stantescu
Refactoring Workflows & Techniques Presentation by Valentin StantescuRefactoring Workflows & Techniques Presentation by Valentin Stantescu
Refactoring Workflows & Techniques Presentation by Valentin Stantescu
 
Dashboards for Business Intelligence
Dashboards for Business IntelligenceDashboards for Business Intelligence
Dashboards for Business Intelligence
 
"Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma...
"Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma..."Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma...
"Open Source ERP Projects and Opportunities for the Romanian Market" by Thoma...
 
NEHA JAIN_RESUME
NEHA JAIN_RESUMENEHA JAIN_RESUME
NEHA JAIN_RESUME
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Introduction to Enterprise Architecture and TOGAF 9.1
Introduction to Enterprise Architecture and TOGAF 9.1Introduction to Enterprise Architecture and TOGAF 9.1
Introduction to Enterprise Architecture and TOGAF 9.1
 
Integrating Zachman and TOGAF-ADM
Integrating Zachman and TOGAF-ADMIntegrating Zachman and TOGAF-ADM
Integrating Zachman and TOGAF-ADM
 
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
 
DRESD Project Presentation - December 2006
DRESD Project Presentation - December 2006DRESD Project Presentation - December 2006
DRESD Project Presentation - December 2006
 
UNIT1_Himani Sharma.pptx
UNIT1_Himani Sharma.pptxUNIT1_Himani Sharma.pptx
UNIT1_Himani Sharma.pptx
 
2015 2016 ieee matlab project titles
2015 2016 ieee matlab project titles2015 2016 ieee matlab project titles
2015 2016 ieee matlab project titles
 
Using a Reputation Framework to Identify Community Leaders in Ontology Engine...
Using a Reputation Framework to Identify Community Leaders in Ontology Engine...Using a Reputation Framework to Identify Community Leaders in Ontology Engine...
Using a Reputation Framework to Identify Community Leaders in Ontology Engine...
 
CS8592_Notes_008_edubuzz360.pdf
CS8592_Notes_008_edubuzz360.pdfCS8592_Notes_008_edubuzz360.pdf
CS8592_Notes_008_edubuzz360.pdf
 

Kürzlich hochgeladen

BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyPooja Nehwal
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxraffaeleoman
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaKayode Fayemi
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMoumonDas2
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 

Kürzlich hochgeladen (20)

BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptx
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 

S.O.L.I.D. Software-Engineering Principles - a must know for developers

  • 1. SOLID Software-Engineering Principles - A must know for developers - Roland Petrasch 5th SET Meet-up Jan. 6, 2016 Bangkok, Thailand
  • 2. Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 2 / 36 SET — Software Engineering Thailand The Interest Group from & (not only) for Developers Open Group: Members, Sponsors and Organizers welcome Next topics: S.O.L.I.D., VR Game Design with Unity, IoT Show Case, Eye Tracking, SE Start-ups: Lessons Learned Contact Roland Petrasch Thammasat University, Department of Computer Science, Rangsit Campus, Pathum Thani roland.petrasch@cs.tu.ac.th roland.petrasch@gmail.com
  • 3. Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 3 / 36 SOLID Software-Engineering Principles Agenda A few Basics, e.g. dependency, coupling, cohesion S.O.L.I.D. Software-Engineering Principles SRP: Responsibilities and OO → OCP Inheritance and Liskov Substitution Principle Modules, components & Interface Segregation Dependency (Abstraction &) Inversion Discussion S O L I D R C S S I P P P P P
  • 4. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 4 / 36 SOLID Basics Modules & components Module → OO: class(es) + interface(s) Component = module(s), package, service Provider → client, interface(s) Encapsulation / information hiding Can be OO (instantiation) or non-OO Dependency Interdependence between software modules Strong, e.g. inheritance, content Weak, e.g. message passing, parameters M D C C
  • 5. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 5 / 36 SOLID Basics Coupling Inter-module aspect: Degree of (in)direct dependencies to other components / modules Example Tight coupling: Component uses implementation Loose coupling: Component uses an abstraction OO: Inheritance Loose coupling is better than tight coupling … normally Source: [4] Rodriguez et al., 2001 M D C C
  • 6. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 6 / 36 SOLID Basics Coupling Example Surveillance App M D C C
  • 7. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 7 / 36 SOLID Basics Cohesion Intra-module aspect: Degree to which the elements of a module belong together Behavior and attributes of a module should “work together” (calsule), i.e. the functions/method a class must use the attributes → high cohesion Otherwise functions/method and attributes do not belong together → low cohesion High cohesion is good, low cohesion is bad … normally M D C C
  • 8. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 8 / 36 SOLID Basics Cohesion Example: class Camera { String name; Integer fps; Integer resolution; Boolean motionTracking; public String getName() { ... } } class CameraController { public String validateSettings() { ... if (fps >= 30 && resolution >= ... } } Low or no cohesion M D C C
  • 9. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 9 / 36 SOLID SE Principles SOLID Bertram Meyer described SE principles, DbC … [1] 5 Principles were introduced in 2000s by Robert C. Martin [3] Principles can lead to better software quality Maintainability Understandability / Readability Correctness M D C C
  • 10. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 10 / 36 SOLID SE Principles SRP – Single Responsibility Principle SRP A class should have only one reason to change Responsibility relates to features and aspects Technological aspects, e.g. output device(s), persistence Domain-oriented aspects, e.g. CRM, production, HR Architectural aspects, e.g. cloud app, mobile client Cohesion and coupling are important underlying concepts for SRP M D C C
  • 11. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 11 / 36 SOLID SE Principles SRP – Single Responsibility Principle Example: entity class and persistence M D C C class Camera { String name; Integer fps; Integer resolution; Boolean motionTracking; public String getName() { ... } public void save() { // some JDBC statements ... } } class CameraDAO { public void save( Camera camera) { ... } } 2 reasons for change: domain & persistence FW class Camera { ... Separation of concerns POJO Data Access Object
  • 12. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 12 / 36 SOLID SE Principles SRP – Single Responsibility Principle DoDOO – Don't destroy Object-Orientation M D C C class Camera { String name; Integer fps; Integer resolution; VDOBuffer buffer; public String getName() { ... } } class CameraLogic { public void record( Camera camera) { ... } public void stream( Camera camera, Stream stream) { ... } } OO Encapsulation: class consists of attributes (data member) and behavior (methods / member functions)
  • 13. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 13 / 36 SOLID SE Principles SRP – Single Responsibility Principle DoMa – The domain matters M D C C class Camera { String OEM; String name; Integer fps; Integer resolution; VDOBuffer buffer; Location location; IP ip; public String getName() { ... } } object Camera1: OEM = “Yamunaki” name = “Y28” fps = 30 Resolution = “1 MPixel” location = “Office” Ip = 1.2.1.1 A camera (type) is not a camera (device) → 2 domain responsibilities object Camera1: OEM = “Yamunaki” name = “Y28” fps = 20 Resolution = “2 MPixel” location = “Floor” Ip = 1.2.1.2 Redundant data, semantic gaps
  • 14. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 14 / 36 SOLID SE Principles SRP – Single Responsibility Principle Use the OOA pattern „spec./product“, “model/exemplar”, “type/object“ M D C C class Camera { String OEM; String name; Integer max_fps; Integer max_resolution; public String getName() { ... } } class CameraDevice { Camera camera; Integer fps; Integer resolution; VDOBuffer buffer; Location location; IP ip; public String record() { ... } 1 * Camera type / spec Camera device / exemplar Many-to-one association. NOT inheritance
  • 15. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 15 / 36 SOLID SE Principles OCP - Open/Closed Principle Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification Use some good 'ol design patterns, e.g. decorator, strategy, wrapper … ? Yes and no: DP can be useful, but OCP goes deeper than that Example: Camera that provides pan, tilt, and zoom functions. Need to change the Camera class? M D C C
  • 16. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 16 / 36 SOLID SE Principles OCP - Open/Closed Principle Camera class should be closed to modifications → „new features“ M D C C class Camera { String OEM; String name; Integer fps; Integer resolution; Angle pan; Angle tilt; Integer zoom; ... } A camera should only be changed for one reason (core functionality / responsibility), not for new feature implementation (SRP).
  • 17. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 17 / 36 SOLID SE Principles OCP - Open/Closed Principle Camera extension … so many possibilities Inheritance Simple Wrapper Decorator M D C C class Camera { ... } class PTZCamera extends Camera { ... } class Camera { ... } class PTZCamera { Camera camera; ... } class IPCamera { ... } class PTZCamera { Camera camera; ... } interface Camera { record() }
  • 18. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 18 / 36 SOLID SE Principles OCP - Open/Closed Principle OCP focuses on class design Strong relationship to SRP, cohesion, and coupling Cohesion should be high when OCP is applied Coupling cannot be avoided, but maybe minimized Avoid over-engineering Coupling is not always so bad as it seems, e.g. domain / entity modeling Using interfaces instead of implementations has advantages, but ask yourself: Do I need this here now or in the future? M D C C
  • 19. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 19 / 36 SOLID SE Principles Liskov Substitution Principle Derived types must be completely substitutable for their base types Strong behavioral subtyping Barbara Liskov and Jeannette Wing, 1994 Derived class can only override the methods of the superclass when the functionality is preserved Example: A Person provides or “uses“ the surveillance system. It can be the OEM, the home owner or an intruder M D C C
  • 20. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 20 / 36 SOLID SE Principles Liskov Substitution Principle Example: M D C C Are we really interested in the birthday of the thief? An OEM probably hasn't a first-name. Does the home owner have attributes?
  • 21. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 21 / 36 SOLID SE Principles Liskov Substitution Principle Example: problems OEM→getFirstName() doesn't really make sense (OEM isn't substitutable for its base type Person) Home owner doesn't have attributes? Really? Intruder/Thief has unknown birthday, first-name etc. (we'll never know) We mixed up 2 concepts: roles and persons Violation of SRP and Liskov substitution principle M D C C
  • 22. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 22 / 36 SOLID SE Principles Liskov Substitution Principle Persons and Roles … so many possibilities Inheritance Simple Role Pattern ... M D C C
  • 23. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 23 / 36 SOLID SE Principles Liskov Substitution Principle System Analysis / OOA is not OOD OOA: “The system identifies intruder an other unwanted persons ...“ LSP applies to OOD, not to OOA M D C C OOA OOD
  • 24. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 24 / 36 SOLID SE Principles ISP Interface Segregation Principle ISP addresses high level architectural aspects A client should never be forced to implement an interface that it doesn’t use A clients shouldn’t be forced to depend on methods it doesn't use Provide specific interfaces to clients (components) Related pattern: facade pattern Example: component interfaces to clients of the surveillance system M D C C
  • 25. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 25 / 36 SOLID SE Principles ISP Interface Segregation Principle Facade provides one common interface to clients → Clients depend on methods they don't need/use M D C C The monitor doesn't need the configuration features.
  • 26. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 26 / 36 SOLID SE Principles ISP Interface Segregation Principle Facade interfaces are specific for clients (SRP) M D C C Interfaces of the component are segregated
  • 27. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 27 / 36 SOLID SE Principles ISP Interface Segregation Principle Camera forces clients to implement methods they don't use M D C C How to implement the CameraControl? A control interface?
  • 28. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 28 / 36 SOLID SE Principles ISP Interface Segregation Principle Camera interfaces should be client-specific, not implementation- specific M D C C Interfaces for different clients
  • 29. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 29 / 36 SOLID SE Principles DIP Dependency Inversion principle High-level modules should not depend on low-level modules Both should depend on abstractions. Abstractions should not depend upon details Details should depend upon abstractions Good example is the DAO pattern Data Access (low-level) depends on abstraction (and on technological modules = libs, FW etc.) Entity classes (high-level) do not depend on DAO M D C C
  • 30. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 30 / 36 SOLID SE Principles DIP Dependency Inversion principle High-level modules should not depend on low-level modules This is also true for inheritance, e.g. Camera (superclass) should never „know“ a subclass PTZCamera. It would detroy the whole hierarchie PTZCamera depends on Camera already and is low-level from the superclass point of view. M D C C
  • 31. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 31 / 36 SOLID SE Principles DIP Dependency Inversion principle Architecture: Business logic is always high-level M D C C BL BL BL BL BL Controller Controller Controller View View View Persistence Persistence Persistence Communication Communication VO VO Programming Language
  • 32. S O L I D R C S S I P P P P P Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 32 / 36 SOLID SE Principles DIP Dependency Inversion principle Why it is called “inversion”? What is inverted? High-level module need other low level modules Example: domain objects need to be persisted, so they depend on these features of low-level module for persistence This dependency (high-level module depend on low-level modules) is inverted, so only low-level modules depend on high-level modules, Example: domain objects are independent of low-level module for persistence services M D C C
  • 33. Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 33 / 36 Discussion SOLID principles are important, but other principles and rules exist, e.g. “No circular dependencies“ rule Tight coupling often causes cyclic dependency Ripple effect: small & local change → “global” effect Source: Agustín Ruiz (espejo)
  • 34. Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 34 / 36 Discussion SOLID is good, but not a simple formula (Principles are not just rules that can be applied) Don't start with metrics, those numbers can be tricky (start with a goal and ideas and principles and …) Check acceptance for SOLID in your team (A hot potato? Lost in Spaghetti code? Good things need time) Maintainability, re-use and understandability are real cost-savers; go the extra mile for SOLID
  • 35. Jan. 6, 2015, Bangkok, Thailand SET Meetup: S.O.L.I.D. Software-Engineering Principles Roland Petrasch, Thammasat University 35 / 36 SOLID Software-Engineering Principles References [1] Bertrand Meyer: Object-Oriented Software Construction. Prentice Hall, 1997 [2] Erich Gamma et al.: Design Patterns: Elements of Reusable Object- Oriented Software. Addison-Wesley, 1994 [3] Robert C. Martin: Agile Software Development, Principles, Patterns, and Practices. Pearson, 2002 [4] Daniel Rodriguez, Rachel Harrison: An Overview of Object-Oriented Design Metrics. RUCS/2001/TR/A, The University Of Reading, 2001 [5] Patkos Csaba: The SOLID Principles. http://code.tutsplus.com/series/the-solid-principles--cms-634 [6] Tigerfreak: Homer Simpson http://s450.photobucket.com/user/tigersafreak/media/homer-simpson-wal lpaper-brain-1024-.jpg.html
  • 36. SOLID Software-Engineering Principles - A must know for developers - Roland Petrasch Thank you for your attention