SlideShare una empresa de Scribd logo
1 de 21
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Some Principles
Stéphane Ducasse --- 2005
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
Open-Close
• Software entities (classes,
• modules, functions, etc.) should
• be open for extension, but closed
• for modification.
S.Ducasse 4
The open-closed principle
• Software entities (classes, modules, functions, etc.)
should be open for extension, but closed for
modification.
• Existing code should not be changed – new features
can be added using inheritance or composition.
S.Ducasse 5
One kind of application
enum ShapeType {circle,
square};
struct Shape {
ShapeType _type;
};
struct Circle {
ShapeType _type;
double _radius;
Point _center;
};
struct Square {
ShapeType _type;
double _side;
Point _topLeft;
};
void
DrawSquare(struct
Square*)
void
DrawCircle(struct
Circle*);
S.Ducasse 6
Example (II)
void DrawAllShapes(struct Shape* list[], int n) {
int i;
for (i=0; i<n; i++) {
struct Shape* s = list[i];
switch (s->_type) {
case square: DrawSquare((struct Square*)s); break;
case circle: DrawCircle((struct Circle*)s); break;
}
}
}
Adding a new shape requires adding new code to this
method.
S.Ducasse 7
Correct Form
class Shape {
public: virtual void Draw() const = 0;
};
class Square : public Shape {
public: virtual void Draw() const;
};
class Circle : public Shape {
public: virtual void Draw() const;
};
void DrawAllShapes(Set<Shape*>& list) {
for (Iterator<Shape*>i(list); i; i++)
(*i)->Draw();
S.Ducasse 8
Some Principles
• Dependency Inversion Principle
• Interface Segregation Principle
• The Acyclic Dependencies Principle
S.Ducasse 9
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.
S.Ducasse 10
Example
void Copy() {
int c;
while ((c = ReadKeyboard()) != EOF)
WritePrinter(c);
}
S.Ducasse 11
Cont...
Now we have a second writing device – disk
enum OutputDevice {printer, disk};
void Copy(outputDevice dev) {
int c;
while ((c = ReadKeyboard()) != EOF)
if (dev == printer)
WritePrinter(c);
else
WriteDisk(c);
}
S.Ducasse 12
Solution
class Reader {
public:
virtual int Read() = 0;
};
class Writer {
public:
virtual void Write(char)=0;
};
void Copy(Reader& r,
Writer& w) {
int c;
while((c=r.Read()) != EOF)
w.Write(c);
}
S.Ducasse 13
Some Principle
S.Ducasse 14
Interface Segregation Principle
• The dependency of one class to another one should
depend on the smallest possible interface.
• Avoid “fat” interfaces
S.Ducasse 15
Examples
S.Ducasse 16
Solutions
• One class one responsibility
• Composition?
S.Ducasse 17
The Acyclic Dependency Principle
• The dependency structure between packages must
not contain cyclic dependencies.
S.Ducasse 18
Example...Ez
S.Ducasse 19
Solutions
• Layering?
• Separation of domain/applicatin/UI
S.Ducasse 20
Packages, Modules and other
• The Common Closure Principle
• Classes within a released component should share
common closure.That is, if one needs to be changed,
they all are likely to need to be changed.
• The Common Reuse Principle
• The classes in a package are reused together. If you
reuse one of the classes in a package, you reuse them all.
S.Ducasse 21
Summary
Build your own taste
Analyze what you write and how?

Más contenido relacionado

La actualidad más candente

4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
The World of Smalltalk
 

La actualidad más candente (16)

9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)
 
9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)
 
04 idioms
04 idioms04 idioms
04 idioms
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
02 basics
02 basics02 basics
02 basics
 
8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
Interactive subway map
Interactive subway mapInteractive subway map
Interactive subway map
 
durability, durability, durability
durability, durability, durabilitydurability, durability, durability
durability, durability, durability
 

Destacado (20)

15 - Streams
15 - Streams15 - Streams
15 - Streams
 
Stoop 433-chain
Stoop 433-chainStoop 433-chain
Stoop 433-chain
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop 413-abstract classes
Stoop 413-abstract classesStoop 413-abstract classes
Stoop 413-abstract classes
 
Stoop 430-design patternsintro
Stoop 430-design patternsintroStoop 430-design patternsintro
Stoop 430-design patternsintro
 
Stoop 439-decorator
Stoop 439-decoratorStoop 439-decorator
Stoop 439-decorator
 
Stoop 400-metaclass only
Stoop 400-metaclass onlyStoop 400-metaclass only
Stoop 400-metaclass only
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
10 reflection
10 reflection10 reflection
10 reflection
 
05 seaside
05 seaside05 seaside
05 seaside
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
Stoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvwStoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvw
 
Stoop 400 o-metaclassonly
Stoop 400 o-metaclassonlyStoop 400 o-metaclassonly
Stoop 400 o-metaclassonly
 
01 intro
01 intro01 intro
01 intro
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
 

Similar a Stoop ed-some principles

Docker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersDocker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for Developers
RapidValue
 
Présentation du projet Moose
Présentation du projet MoosePrésentation du projet Moose
Présentation du projet Moose
Stefane Fermigier
 
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2   Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Adil Khan
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?
Sergei Stryukov
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
Sri Prasanna
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
 

Similar a Stoop ed-some principles (20)

Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 
Docker and coreos20141020b
Docker and coreos20141020bDocker and coreos20141020b
Docker and coreos20141020b
 
Docker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersDocker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for Developers
 
CUDA Tutorial 01 : Say Hello to CUDA : Notes
CUDA Tutorial 01 : Say Hello to CUDA : NotesCUDA Tutorial 01 : Say Hello to CUDA : Notes
CUDA Tutorial 01 : Say Hello to CUDA : Notes
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Présentation du projet Moose
Présentation du projet MoosePrésentation du projet Moose
Présentation du projet Moose
 
Drush A beginners guide to a advanced tool.
Drush A beginners guide to a advanced tool.Drush A beginners guide to a advanced tool.
Drush A beginners guide to a advanced tool.
 
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
 
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2   Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
The maze of Design Patterns & SOLID Principles
The maze of Design Patterns & SOLID PrinciplesThe maze of Design Patterns & SOLID Principles
The maze of Design Patterns & SOLID Principles
 
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin PiebiakWorkflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
 
Workflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large Enterprises
 
C++ development within OOo
C++ development within OOoC++ development within OOo
C++ development within OOo
 
Achieving Full Stack DevOps at Colonial Life
Achieving Full Stack DevOps at Colonial Life Achieving Full Stack DevOps at Colonial Life
Achieving Full Stack DevOps at Colonial Life
 
OCCIware Year 1 Milestone: Docker Studio, Studio Factory, pluggable XaaS runt...
OCCIware Year 1 Milestone: Docker Studio, Studio Factory, pluggable XaaS runt...OCCIware Year 1 Milestone: Docker Studio, Studio Factory, pluggable XaaS runt...
OCCIware Year 1 Milestone: Docker Studio, Studio Factory, pluggable XaaS runt...
 
OCCIware Cloud Expo London 2016 - Docker Studio, Studio Factory, erocci bus &...
OCCIware Cloud Expo London 2016 - Docker Studio, Studio Factory, erocci bus &...OCCIware Cloud Expo London 2016 - Docker Studio, Studio Factory, erocci bus &...
OCCIware Cloud Expo London 2016 - Docker Studio, Studio Factory, erocci bus &...
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
 

Más de The World of Smalltalk (12)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
06 debugging
06 debugging06 debugging
06 debugging
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Stoop ed-some principles

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.listic.univ-savoie.fr/~ducasse/ Some Principles Stéphane Ducasse --- 2005
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 Open-Close • Software entities (classes, • modules, functions, etc.) should • be open for extension, but closed • for modification.
  • 4. S.Ducasse 4 The open-closed principle • Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. • Existing code should not be changed – new features can be added using inheritance or composition.
  • 5. S.Ducasse 5 One kind of application enum ShapeType {circle, square}; struct Shape { ShapeType _type; }; struct Circle { ShapeType _type; double _radius; Point _center; }; struct Square { ShapeType _type; double _side; Point _topLeft; }; void DrawSquare(struct Square*) void DrawCircle(struct Circle*);
  • 6. S.Ducasse 6 Example (II) void DrawAllShapes(struct Shape* list[], int n) { int i; for (i=0; i<n; i++) { struct Shape* s = list[i]; switch (s->_type) { case square: DrawSquare((struct Square*)s); break; case circle: DrawCircle((struct Circle*)s); break; } } } Adding a new shape requires adding new code to this method.
  • 7. S.Ducasse 7 Correct Form class Shape { public: virtual void Draw() const = 0; }; class Square : public Shape { public: virtual void Draw() const; }; class Circle : public Shape { public: virtual void Draw() const; }; void DrawAllShapes(Set<Shape*>& list) { for (Iterator<Shape*>i(list); i; i++) (*i)->Draw();
  • 8. S.Ducasse 8 Some Principles • Dependency Inversion Principle • Interface Segregation Principle • The Acyclic Dependencies Principle
  • 9. S.Ducasse 9 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.
  • 10. S.Ducasse 10 Example void Copy() { int c; while ((c = ReadKeyboard()) != EOF) WritePrinter(c); }
  • 11. S.Ducasse 11 Cont... Now we have a second writing device – disk enum OutputDevice {printer, disk}; void Copy(outputDevice dev) { int c; while ((c = ReadKeyboard()) != EOF) if (dev == printer) WritePrinter(c); else WriteDisk(c); }
  • 12. S.Ducasse 12 Solution class Reader { public: virtual int Read() = 0; }; class Writer { public: virtual void Write(char)=0; }; void Copy(Reader& r, Writer& w) { int c; while((c=r.Read()) != EOF) w.Write(c); }
  • 14. S.Ducasse 14 Interface Segregation Principle • The dependency of one class to another one should depend on the smallest possible interface. • Avoid “fat” interfaces
  • 16. S.Ducasse 16 Solutions • One class one responsibility • Composition?
  • 17. S.Ducasse 17 The Acyclic Dependency Principle • The dependency structure between packages must not contain cyclic dependencies.
  • 19. S.Ducasse 19 Solutions • Layering? • Separation of domain/applicatin/UI
  • 20. S.Ducasse 20 Packages, Modules and other • The Common Closure Principle • Classes within a released component should share common closure.That is, if one needs to be changed, they all are likely to need to be changed. • The Common Reuse Principle • The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.
  • 21. S.Ducasse 21 Summary Build your own taste Analyze what you write and how?