Afstudeer presentatie: Solid design

2,591 views
2,471 views

Published on

Presentatie gegeven tijdens verdediging van afstudeertraject. Afstuderen was in het kader van HBO opleiding Informatica aan de Haagse Hogeschool.

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

  • Be the first to like this

No Downloads
Views
Total views
2,591
On SlideShare
0
From Embeds
0
Number of Embeds
1,129
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Afstudeer presentatie: Solid design

  1. 1. Building your application SOLID Paul de Raaij | @pderaaij 2-2-2012
  2. 2. Student HHS
  3. 3. Afstudeerder
  4. 4. Korte introductie• Afstuderen bij Eleven
  5. 5. Toolbox
  6. 6. Formulierenmodule
  7. 7. DESIGN
  8. 8. SOLID software design
  9. 9. SOLID Design• Vijf essentiële principes• Geïntroduceerd door Robert C. MartinPr i n c i p l e s o f O b j e c t -O r i e n t e d d
  10. 10. Waarom SOLIDdesign?
  11. 11. Loosely coupled
  12. 12. High cohesion
  13. 13. Reusable
  14. 14. Maintainable
  15. 15. Testable
  16. 16. Waar staat het voor• Single Responsibility Principle• Open/Closed Principle• Liskov Substitution Principle• Interface Segregation Principle• Dependency Inversion Principle
  17. 17. Single Responsibility PrincipleEen klasse heeft maar één reden om te wijzigen
  18. 18. Single Responsibility Principle1. public class Employee {2. public BigDecimal pay();3. public String getFullName();4. public float getWorkedHours();5. }
  19. 19. Single Responsibility Principle1. public class Employee {2. public String getFullName();3. }4.5. public class Cashier {6. public void pay(Employee e);7. }8.9. public class EmployeeReporter {10. public float getWorkedHours(Employee e);11.}
  20. 20. Open/Closed principle Entiteiten moeten gesloten zijn voorwijzigingen, maar open voor uitbreidingen
  21. 21. Open/Closed principle1. public class Musician {2. public void playGuitar();3. }
  22. 22. Open/Closed principle1. public class Musician {2. public void playGuitar();3. public void playPiano();4. }
  23. 23. Open/Closed principle1. public class Musician {2. public void playInstrument(Instrument i);3. }4.5. interface Instrument {6. public void play();7. }8.9. public class Guitar implements Instrument {10. public void play();11.}12.13.public class Piano implements Instrument {14. public void play();15.}
  24. 24. Liskov Substitution PrincipleFuncties die gebruik maken van een basis klassemoeten feilloos werken als een afgeleide klasse wordt gebruikt
  25. 25. Liskov Substitution Principle1. class Rectangle {2. public int width;3. public int height;4.5. public void setWidth(int w) {}6. public void setHeight(int h) {}7. public int getArea() { return h*w; }8. }9.10. class Square extends Rectangle {11. public void setWidth( int w ) { super.setWidth(w); super.setHeight(w); }12. public void setHeight( int h ) { super.setWidth(h); super.setHeight(h); }13. }14.15. class TestProgram {16. Rectangle r = new Rectangle();17. r.setWidth(5); r.setHeight(4);18. r.getArea(); // returns 2019.20. Square s = new Square();21. s.setWidth(5); s.setHeight(4);22. s.getArea(); // returns 16;23. }
  26. 26. Interface Segregation Principle Functie-specifieke interfaces zijn beter dan één generieke interface
  27. 27. Interface Segregation Principle1. interface Animal {2. public void bark();3. public void fly();4. public void run();5. public void eatPlant();6. public void eatMeat();7. }8.9. public Dog implements Animal {10. public void bark();11. public void run();12. public void eatPlant();13. public void eatMeat();14. }15.16. public Duck implements Animal {17. public void fly();18. public void eatPlant();19. }
  28. 28. 1. interface Barkable {2. public void bark();3. }4.5. interface Flyable {6. public void fly();7. }8.9. interface Runnable {10. public void run();11. }12.13. interface Herbivore() {14. public void eatPlant();15. }16.17. interface Carnivore() {18. public void eatMeat();19. }20.21. public Dog implements Barkable, Runnable, Herbivore, Carnivore {22. public void bark();23. public void run();24. public void eatPlant();25. public void eatMeat();26. }27.28. public Duck implements Flyable, Herbivore {29. public void fly();30. public void eatPlant();31. }
  29. 29. Dependency Inversion Principle A) High level modules mogen niet afhankelijk zijn van low level modules, beide moeten afhangen van abstracties B) Abstracties mogen niet afhangen van details, details moeten afhangen van abstracties
  30. 30. Dependency Inversion Principle1. class Band {2. private Singer = new Singer();3. private Musician = new Musician();4.5. public void playSong();6. }
  31. 31. Dependency Inversion Principle1. interface MusicalTalent {2. public void useTalent();3. }4.5. class Musician implements MusicalTalent() {}6. class Singer implements MusicalTalent() {}7. class SingingGuitarist implements MusicalTalent() {}8.9. class Band {10. public void playSong( MusicalTalent mt ) {11. mt.useTalent();12. }13. }
  32. 32. Dependency Inversion Principle1. interface MusicalTalent {2. public void useTalent();3. }4.5. class Musician implements MusicalTalent() {}6. class Singer implements MusicalTalent() {}7. class SingingGuitarist implements MusicalTalent() {}8.9. class Band {10. private List<MusicalTalent> members = new ArrayList<MusicalTalent>();11. public Band() {}12. public void addMember( MusicalTalent mt ) {13. members.add( mt );14. }15.16. public void playSong() {}17. }
  33. 33. SOLID
  34. 34. Nooit alleen…
  35. 35. … Sterk aan elkaargekoppeld
  36. 36. Perfect ontwerp bestaat niet SOLID helpt de balans te vinden

×