object design - irisapeople.irisa.fr/francois.schwarzentruber/mit2_cvfp_2013/object_desi… ·...
TRANSCRIPT
![Page 1: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/1.jpg)
Object design
François SchwarzentruberENS Cachan – Antenne de Bretagne
![Page 2: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/2.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture● Dreams
![Page 3: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/3.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture● Dreams
![Page 4: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/4.jpg)
Symptoms of rotting systems (according to Robert C. Martin)
Four possible unsuitable behaviors of the developer team:
● Rigidity
● Fragility
● Immobility
● Viscosity
![Page 5: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/5.jpg)
Rigidity
System
Add functionality 1
Add functionality 2
Add functionality 3
![Page 6: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/6.jpg)
Rigidity
Could you please addthe undo feature?
Yes I will implement it
![Page 7: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/7.jpg)
Rigidity
![Page 8: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/8.jpg)
Rigidity
Ok... let us forgetabout it...
I am sorry... it willtake several months
to do it!
This functionality will never be implemented.
![Page 9: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/9.jpg)
Fragility
Add functionality
![Page 10: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/10.jpg)
Fragility
Could you please addthe undo feature?
Yes I will implement it.
![Page 11: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/11.jpg)
Fragility
![Page 12: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/12.jpg)
Fragility
Oh :(But you already changed 3 times
the structure of the softwarefor all the 3 featureswe have told about!
I have done it!1) I completely changed the structure.
2) I implemented it...
The developer team is not to be trusted.
![Page 13: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/13.jpg)
Immobility
rewrite
AlreadyExistingpackage
reuse
![Page 14: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/14.jpg)
Immobility
I need a scheme evaluator...
Oh! Here is a completescheme library for JAVA.
SchemeJ
A completescheme library
for JAVA !
Opensource
>(+ 1 2)3
![Page 15: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/15.jpg)
Immobility
I will try to findthe scheme evaluator from it...
SchemeJ
A completescheme library
for JAVA !
Opensource
![Page 16: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/16.jpg)
Immobility
I do not understand anything.
SchemeJ
A completescheme library
for JAVA !Open
source
I will write my own interpreter...
![Page 17: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/17.jpg)
Viscosity
system
hack
Apply gooddesign principles
![Page 18: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/18.jpg)
Viscosity
![Page 19: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/19.jpg)
Viscosity - example
Extract from a MIT2 internship report
![Page 20: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/20.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture● Dreams
![Page 21: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/21.jpg)
SOLID
● 5 principles of object oriented class design
● Introduced by Robert Cecil Martin
![Page 22: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/22.jpg)
S : Single responsibility principle
There should never be more than one reason for aclass to change.
● Class of a game:
- that computes the position of enemies
- that computes the score
● Class of a game that uses two objects:
- one that computes the position of enemies
- another that computes the score
Change the gravity ?
Change the way ofcounting the score ?
![Page 23: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/23.jpg)
S : Single responsibility principle
There should never be more than one reason for aclass to change.
Change the gravity ?
Change the way ofcounting the score ?
I do gravity... After your modification,I modify the
score definition.
Or I implement both...
I modify GravityManager. I modify
ScoreManager.
![Page 24: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/24.jpg)
S : Single responsibility principle
There should never be more than one reason for aclass to change.
Change the gravity ?
Change the way ofcounting the score ?
I proposetwo gravity modes...
I proposetwo scoremodes...
![Page 25: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/25.jpg)
O : Open Closed Principle
● Change the code source of module to add functionnality
● Being able to extend modules without changing the code source
→ abstraction
![Page 26: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/26.jpg)
O : Open Closed Principle
Class Enemy{
void move(){
if(type == RABBIT)...
else if(type == BROWSER)...
else if(type == MUSHROOM)...
}}
![Page 27: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/27.jpg)
O : Open Closed Principle
Class Enemy{
void move(){
if(type == RABBIT)...
else if(type == BROWSER)...
else if(type == MUSHROOM)...
}} For each change of
a type of enemy, I recompile all
the class Enemy...
Oh I just recompileone class...
![Page 28: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/28.jpg)
O : Open Closed Principle
Class Enemy{
void move(){
if(type == RABBIT)...
else if(type == BROWSER)...
else if(type == MUSHROOM)...
}
void jump(){
if(type == RABBIT)...
else if(type == BROWSER)...
else if(type == MUSHROOM)...
} . . .}
If I add a new type of enemy,
I check all the if/elsestatements...
Oh I just adda new class...
![Page 29: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/29.jpg)
L : Liskov Substitution Principle
Barbara LiskovTuring award 2008
or
?
![Page 30: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/30.jpg)
L : Liskov Substitution Principle
![Page 31: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/31.jpg)
L : Liskov Substitution Principle
But a circle is simplier...And we extend it to
make a ellipse...It seems reasonable...
![Page 32: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/32.jpg)
L : Liskov Substitution Principle
But a circle is simplier...And we extend it to
make a ellipse...
Class Circle{
public float getR();public float getArea();
}
Class Ellipse extends Circle{
...}
Circle c;c = new Ellipse(...);
/* Here we expect thatthe area of c isc.getR()^2 * PI*/
![Page 33: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/33.jpg)
L : Liskov Substitution Principleand design by contract
Class Ellipse{
public float getR1();public float getR2();public float getArea();
}
Class Circle extends Ellipse{
...}
Ellipse e;e = new Circle(...);
/* Here we expect thatthe area of e isc.getR1() * c.getR2() * PI*/
![Page 34: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/34.jpg)
L : Liskov Substitution Principleand design by contract
Class Ellipse{
invariant: inv
precondition: prepostcondition: posvoid f(Point p1, p2){}:
}
Class Circle extends Ellipse{
invariant: stronger than inv
precondition: weaker than prepostcondition: stronger than posvoid f(Point p1, p2){}:
}
![Page 35: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/35.jpg)
L : Liskov Substitution Principleand design by contract
Class Ellipse{
void setFocus(Point p1, p2){
this.p1 = p1;this.p2 = p2;
}:
}
Class Circle extends Ellipse{
void setFocus(Point p1, p2){
this.p1 = p1;this.p2 = p1;
}:
}
:
![Page 36: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/36.jpg)
A little problem
Class Ellipse{
postcondition: this.p1 == p1 & this.p2 == p2
void setFocus(Point p1, p2){
this.p1 = p1;this.p2 = p2;
}:
}
Class Circle extends Ellipse{
void setFocus(Point p1, p2){
this.p1 = p1;this.p2 = p1;
}:
}
:
!
Ellipse e = new Circle();e.setFocus(p1, p2);
assert(e.getP1() == p1);assert(e.getP2() == p2);
![Page 37: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/37.jpg)
I : Interface Segregation Principle
I am plumber...
I am an electrical fitter.
Here is the entire mapof the house.
I am plumber...
I am an electrical fitter.
I propose an interfacefor accessing to pipes.
I propose an interfacefor accessing to cables.
![Page 38: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/38.jpg)
I : Interface Segregation Principle
I am plumber...
I am an electrical fitter.
Here is the entire mapof the house.
I am plumber...
I am an electrical fitter.
I propose an interfacefor accessing to pipes.
I propose an interfacefor accessing to cables.
I understand better.I do not understand.
![Page 39: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/39.jpg)
I : Interface Segregation Principle
I am plumber...
I am an electrical fitter.
Here is the entire mapof the house.
I am plumber...
I am an electrical fitter.
I propose an interfacefor accessing to pipes.
I propose an interfacefor accessing to cables.
Oh no...
I do not understand the map.
I changed the pipes...
OK.
![Page 40: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/40.jpg)
D: Dependency Inversion Principle
I make a web servicefor booking flights.
And what about trains?
I make a web servicefor booking abstract
travels.
Perfect!
Ok... I will implementit for flights.
I propose an interfacethat specifies
what an abstract travel is.Cool... I like flights.
Ok... I will implementit for trains.
Oh no...
![Page 41: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/41.jpg)
D: Dependency Inversion Principle
Example:
● JAVA MidiSound
MIDIPlayer I_Synthesizer
Synthesizer Mechanical Piano
![Page 42: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/42.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture● Dreams
![Page 43: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/43.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture
● Inside a package● Between packages
● Dreams
![Page 44: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/44.jpg)
Remark
We refactor the packages during the development:
● At the beginning stage, we favor the developer
● At the end, we favor the clients.
![Page 45: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/45.jpg)
The Release Reuse Equivalency Principle
A package
● the granule of reuse
● the granule of release
● Number of versions
● Should support and maintain older versions
Goodfor the client!
1.12 1.13 2.0
![Page 46: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/46.jpg)
The Common Closure Principle
Classes that change together, belong together.
And we need to change here too!
Change !!
Goodfor the
developer!
Packages tend to be large.
![Page 47: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/47.jpg)
The Common Closure Principle
Classes that change together, belong together.
And we need to change here too!
Change !!
Goodfor the
developer!
Packages tend to be large.
dev
Mess for testing, etc.
![Page 48: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/48.jpg)
The Common Reuse Principle
Classes that aren’t reused together should not be grouped together.
Change !!
client
Oh no... you modifya class I don't care
…But I must still test myimplementation that
depends on your $%!$ package !
client
Change !!
Goodfor the client!
Packages tend to be small.
client
![Page 49: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/49.jpg)
Cohesion
![Page 50: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/50.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture
● Inside a package● Between packages
● Dreams
![Page 51: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/51.jpg)
Coupling
![Page 52: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/52.jpg)
The Acyclic Dependencies Principle
The dependencies between packages must not form cycles.
I work on Protocol...and I need to testmy package with
Comm Error.
![Page 53: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/53.jpg)
The Acyclic Dependencies Principle
The dependencies between packages must not form cycles.
I work on Protocol...and I need to testmy package withall the packages !
![Page 54: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/54.jpg)
Solution: Dependency Inversion Principle
![Page 55: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/55.jpg)
Solution: Dependency Inversion Principle
GUI
MessageManager
Comm Error
ConcreteMessageDisplayer
I_MessageDisplayer MessageManager
ErrorManager
![Page 56: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/56.jpg)
The Stable Dependencies Principle
Depend in the direction of stability
My work dependson package X !
I need to modify X..because it is related to
other packages...because it is a difficult
part of the project...
Oh no... X is not stable...
My work dependson package X !
Good point. X will notChange anymore.
X is stable !
![Page 57: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/57.jpg)
Stable / instable
Y instableX stable
![Page 58: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/58.jpg)
The stable abstractions principle
Stable packages should be abstract packages.
Flexible / instable
Stable
![Page 59: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/59.jpg)
The stable abstractions principle
Stable packages should be abstract packages.
Flexible / instable
Stable→ but we want them flexible→ should be abstract in order to be extended!
![Page 60: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/60.jpg)
Outline
● Symptoms of rotting systems● Principles of object oriented class design● Principles of Package Architecture● Dreams
![Page 61: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/61.jpg)
Dream 1: Automated assistance
Software to help you to design the architecture X
warning:no abstractenough
![Page 62: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/62.jpg)
Measuring instability
i
![Page 63: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/63.jpg)
Measuring abstractness
![Page 64: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/64.jpg)
The zone of pain: stable and too concrete
Graphical libraryfor Android 3.0
Map Player
![Page 65: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/65.jpg)
The main sequence: stability = abstractness
GeneralGraphical library
Map Player
![Page 66: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/66.jpg)
The zone of uselessness: abstract but not used!
GeneralGraphical library
![Page 67: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/67.jpg)
Instability VS Abstractness
![Page 68: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/68.jpg)
Dream 2: creating automatically the packages partition
Graph of dependencies G = (V, E)
![Page 69: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/69.jpg)
Dream 2: creating automatically the packages partition
![Page 70: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/70.jpg)
Dream 2: creating automatically the packages partition
A new field
● [Mitchell 2002]
● Bunch [Mitchell et al. 2006]
● Nothing about stability and abstractness
● Preliminary work...
![Page 71: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/71.jpg)
Related problems
P:
● Minimal cut by flow algorithms
= finding two packages with low coupling
NP:
● Graph partitioning (minimal cut plus a constraint over the size of the packages)
= finding two `big' packages with low coupling
● The clique problem, NP-complete
= find a package with high cohesion
![Page 72: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/72.jpg)
Mitchell's PhD
● Measuring cohesion
● Measuring coupling
● Measuring the quality of a clustering
![Page 73: Object design - IRISApeople.irisa.fr/Francois.Schwarzentruber/mit2_cvfp_2013/object_desi… · Object design François ... Class of a game that uses two objects: - one that computes](https://reader030.vdocuments.net/reader030/viewer/2022040917/5e91c7f372e24021a461e0f4/html5/thumbnails/73.jpg)
Heuristics
● Hill-climbing algorithms
● Genetic algorithms
PS: People claim the problem is NP-complete (I want a proof)