Your SlideShare is downloading. ×
0
Stoop ed-inheritance composition
Stoop ed-inheritance composition
Stoop ed-inheritance composition
Stoop ed-inheritance composition
Stoop ed-inheritance composition
Stoop ed-inheritance composition
Stoop ed-inheritance composition
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Stoop ed-inheritance composition

257

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
257
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Stéphane Ducasse Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ 1 Elements of Design - Inheritance/Compositio n
  • 2. S.Ducasse 2 A Formating Text Editor With several possible algorithms formatWithTex formatFastColoring formatSlowButPreciseColoring
  • 3. S.Ducasse 3 Code Smells Composition>>repair formatting == #Simple ifTrue: [ self formatWithSimpleAlgo] ifFalse: [ formatting == #Tex ifTrue: [self formatWithTex] ....]
  • 4. S.Ducasse 4 Inheritance? May not be the solution since: - you have to create objects of the right class - it is difficult to change the policy at run-time - you can get an explosion of classes bloated with the use of a functionality and the functionalities. - no clear identification of responsibility
  • 5. S.Ducasse 5 Inheritance vs. Composition Inheritance is not a panacea Require class definition Require method definition Extension should be prepared in advance No run-time changes Ex: editor with spell-checkerS, colorizerS, mail- readerS…. No clear responsibility Code bloated Cannot load a new colorizers
  • 6. S.Ducasse 6 Delegating to other Objects myEditor setColorizer: FastColorizer new. myEditor setColorizer: AdvancedColorizer new. Strategy design pattern
  • 7. S.Ducasse 7 Composition Analysis Pros Possibility to change at run-time Clear responsibility No blob Clear interaction protocol Cons New class Delegation New classes

×