SlideShare ist ein Scribd-Unternehmen logo
1 von 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?

Weitere ähnliche Inhalte

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Stoop ed-some principles

Docker and coreos20141020b
Docker and coreos20141020bDocker and coreos20141020b
Docker and coreos20141020bRichard Kuo
 
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 DevelopersRapidValue
 
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 : NotesSubhajit Sahu
 
Présentation du projet Moose
Présentation du projet MoosePrésentation du projet Moose
Présentation du projet MooseStefane Fermigier
 
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.Mediacurrent
 
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...7mind
 
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 ProgrammingSri Prasanna
 
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 PrinciplesMuhammad Raza
 
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 EnterprisesPuppet
 
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 PiebiakNETWAYS
 
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 DevOps.com
 
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
 
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 &...Marc Dutoo
 

Ähnlich wie 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
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large Enterprises
 
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
 
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 &...
 
Intro to Drush
Intro to DrushIntro to Drush
Intro to Drush
 

Mehr von 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
 

Kürzlich hochgeladen

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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)wesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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 WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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.pptxHampshireHUG
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Kürzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

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?