SlideShare a Scribd company logo
1 of 31
Encapsulationthe good, the bad, the ugly EigelSilviu-Horea, silviu.eigel@endava.com 		   www.endava.com 16 Octombrie2010
Agenda From functional decomposition to OOP Encapsulation From bad and ugly to “The Good” Building up encapsulation Handling variation Conclusions
Some values Cohesion How closely the operations in a module are related Coupling  The strength of a  connection between  two modules
Some problems Requirements Always Change Change is necessary New variation to an existing theme
Back in the days Professor and students  Functional decomposition Lasagna
OOP Objects as data with methods Classes are things with responsibilities Abstraction Encapsulation Inheritance Polymorphism
The bad in its “definition” Usually defined as data hiding
The ugliness is in our usage Still functionally decomposing Caused by it’s natural roots Data hiding view Data - functionality separation
E as hiding Instead think of E as Hiding – any kind of hiding Implementation Derived classes Design details Instantiation rules Hide things  Why? What you hide you can change
E as hiding
The evil of the global variable The lowest degree of encapsulation Foo.field same as Global.field Ignores all the efforts of C#/Java creators Tight coupling
The evil of the global variable To depend on field a Foo is necessary Coupling through field requires a reference to the same instance of Foo Removing ‘public’ is another encapsulating action
The evil of the global variable
E of member identity Bar coupled to:  field’ ’s value fieldis an integer field  is an instance member of Foo Identity coupling: A knows that B exists
E of member identity
E of member identity Create method/property that E field ’s nature Bar is coupled only to the fact that  Prop is an integer property Bar is decoupled from the fact that: field is an integer field is in Foo field is stored anywhere at all
E of member identity
Self-Encapsulating members Standard practice for accessing a field within the class itself is to refer to it directly
E of type Hiding of entire types CalcUser contains no mention of Adder or Multiplier Calculator E its subclasses GOF – “design to interfaces”
E of design Someone has to new Adder or Multiplier Someone has to decide which one to build Client having this responsibility Breaks the E of type Lose modularity Object factory
E of design The Strategy Pattern itself is not E If design changes Hide the design Context requests Strategy from StrategyFactory instead of Client Have a factory build the Context object handing proper Strategy
E of variation Animals Types of moving Walking Flying Switches Subclasses More variation Herbivores Carnivores
E of variation
Difficulty of E reference objects **Demo**
Difficulty of E reference objects myFoo is not fully encapsulated Bar ’s behavior depends on the state of Foo reference Client can break E if it retains the Foo reference
Breaking E
Breaking E Tell don’t ask Still exposes internal structure of the component Client has to manage explicitly Hide how money are displayed
Issues in E We might say: “Encapsulate the name of the application’s log file in the PricingPolicy class.” Recast in terms of information hiding: “Hide the name of the application’s log file in the PricingPolicy class.” Information can be hidden in the wrong place
Values in E Promotes High cohesion Freedom in changing things Clarity Low coupling Testability
Resources Design Patterns Explained  A New Perspective on  Object-Oriented Design  Design Patterns  Elements of Reusable  Object-Oriented Software Code Complete
Please fill the evaluation form Thank you very much EigelSilviu-Horea,  silviu.eigel@endava.com

More Related Content

Similar to Encapsulation CodeCampIasi 16 oct 2010

Solid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesSolid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesFederico Damián Lozada Mosto
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docxFredWauyo
 
Reactive design: languages, and paradigms
Reactive design: languages, and paradigmsReactive design: languages, and paradigms
Reactive design: languages, and paradigmsDean Wampler
 
Object Oriented Concepts in Real Projects
Object Oriented Concepts in Real ProjectsObject Oriented Concepts in Real Projects
Object Oriented Concepts in Real ProjectsEPAM
 
Metamorphosis from Forms to Java: a technical lead's perspective
Metamorphosis from Forms to Java:  a technical lead's perspectiveMetamorphosis from Forms to Java:  a technical lead's perspective
Metamorphosis from Forms to Java: a technical lead's perspectiveMichael Fons
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - EncapsulationMichael Heron
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
JAVA - Oops Concept.pptx
JAVA - Oops Concept.pptxJAVA - Oops Concept.pptx
JAVA - Oops Concept.pptxayankamila005
 
Methods for Ontology Design Patterns reuse
Methods for Ontology Design Patterns reuseMethods for Ontology Design Patterns reuse
Methods for Ontology Design Patterns reuseValentina Presutti
 
An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)
An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)
An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)Bart Feenstra
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptxUmerUmer25
 
Clean Code .Net Cheetsheets
Clean Code .Net CheetsheetsClean Code .Net Cheetsheets
Clean Code .Net CheetsheetsNikitaGoncharuk1
 

Similar to Encapsulation CodeCampIasi 16 oct 2010 (20)

Solid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesSolid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examples
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docx
 
Reactive design: languages, and paradigms
Reactive design: languages, and paradigmsReactive design: languages, and paradigms
Reactive design: languages, and paradigms
 
OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Lecture01
Lecture01Lecture01
Lecture01
 
Object Oriented Concepts in Real Projects
Object Oriented Concepts in Real ProjectsObject Oriented Concepts in Real Projects
Object Oriented Concepts in Real Projects
 
Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
Metamorphosis from Forms to Java: a technical lead's perspective
Metamorphosis from Forms to Java:  a technical lead's perspectiveMetamorphosis from Forms to Java:  a technical lead's perspective
Metamorphosis from Forms to Java: a technical lead's perspective
 
Solid
SolidSolid
Solid
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - Encapsulation
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 
JAVA - Oops Concept.pptx
JAVA - Oops Concept.pptxJAVA - Oops Concept.pptx
JAVA - Oops Concept.pptx
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Methods for Ontology Design Patterns reuse
Methods for Ontology Design Patterns reuseMethods for Ontology Design Patterns reuse
Methods for Ontology Design Patterns reuse
 
An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)
An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)
An Introduction to Object-Oriented Programming (SaunaCamp Helsinki 2015)
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptx
 
OOP Lecture 01.pptx
OOP Lecture 01.pptxOOP Lecture 01.pptx
OOP Lecture 01.pptx
 
Clean Code .Net Cheetsheets
Clean Code .Net CheetsheetsClean Code .Net Cheetsheets
Clean Code .Net Cheetsheets
 

More from Codecamp Romania

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experienceCodecamp Romania
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-packCodecamp Romania
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pegaCodecamp Romania
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseCodecamp Romania
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10 Codecamp Romania
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous deliveryCodecamp Romania
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2dCodecamp Romania
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdomCodecamp Romania
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...Codecamp Romania
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowCodecamp Romania
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in androidCodecamp Romania
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing careerCodecamp Romania
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkitCodecamp Romania
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forwardCodecamp Romania
 

More from Codecamp Romania (20)

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experience
 
Cloud powered search
Cloud powered searchCloud powered search
Cloud powered search
 
Ccp
CcpCcp
Ccp
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-pack
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pega
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabase
 
Agility and life
Agility and lifeAgility and life
Agility and life
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10
 
The bigrewrite
The bigrewriteThe bigrewrite
The bigrewrite
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous delivery
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2d
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdom
 
Scale net apps in aws
Scale net apps in awsScale net apps in aws
Scale net apps in aws
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflow
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in android
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing career
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
 
Ecma6 in the wild
Ecma6 in the wildEcma6 in the wild
Ecma6 in the wild
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forward
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Encapsulation CodeCampIasi 16 oct 2010

  • 1. Encapsulationthe good, the bad, the ugly EigelSilviu-Horea, silviu.eigel@endava.com www.endava.com 16 Octombrie2010
  • 2. Agenda From functional decomposition to OOP Encapsulation From bad and ugly to “The Good” Building up encapsulation Handling variation Conclusions
  • 3. Some values Cohesion How closely the operations in a module are related Coupling The strength of a connection between two modules
  • 4. Some problems Requirements Always Change Change is necessary New variation to an existing theme
  • 5. Back in the days Professor and students Functional decomposition Lasagna
  • 6. OOP Objects as data with methods Classes are things with responsibilities Abstraction Encapsulation Inheritance Polymorphism
  • 7. The bad in its “definition” Usually defined as data hiding
  • 8. The ugliness is in our usage Still functionally decomposing Caused by it’s natural roots Data hiding view Data - functionality separation
  • 9. E as hiding Instead think of E as Hiding – any kind of hiding Implementation Derived classes Design details Instantiation rules Hide things Why? What you hide you can change
  • 11. The evil of the global variable The lowest degree of encapsulation Foo.field same as Global.field Ignores all the efforts of C#/Java creators Tight coupling
  • 12. The evil of the global variable To depend on field a Foo is necessary Coupling through field requires a reference to the same instance of Foo Removing ‘public’ is another encapsulating action
  • 13. The evil of the global variable
  • 14. E of member identity Bar coupled to: field’ ’s value fieldis an integer field is an instance member of Foo Identity coupling: A knows that B exists
  • 15. E of member identity
  • 16. E of member identity Create method/property that E field ’s nature Bar is coupled only to the fact that Prop is an integer property Bar is decoupled from the fact that: field is an integer field is in Foo field is stored anywhere at all
  • 17. E of member identity
  • 18. Self-Encapsulating members Standard practice for accessing a field within the class itself is to refer to it directly
  • 19. E of type Hiding of entire types CalcUser contains no mention of Adder or Multiplier Calculator E its subclasses GOF – “design to interfaces”
  • 20. E of design Someone has to new Adder or Multiplier Someone has to decide which one to build Client having this responsibility Breaks the E of type Lose modularity Object factory
  • 21. E of design The Strategy Pattern itself is not E If design changes Hide the design Context requests Strategy from StrategyFactory instead of Client Have a factory build the Context object handing proper Strategy
  • 22. E of variation Animals Types of moving Walking Flying Switches Subclasses More variation Herbivores Carnivores
  • 24. Difficulty of E reference objects **Demo**
  • 25. Difficulty of E reference objects myFoo is not fully encapsulated Bar ’s behavior depends on the state of Foo reference Client can break E if it retains the Foo reference
  • 27. Breaking E Tell don’t ask Still exposes internal structure of the component Client has to manage explicitly Hide how money are displayed
  • 28. Issues in E We might say: “Encapsulate the name of the application’s log file in the PricingPolicy class.” Recast in terms of information hiding: “Hide the name of the application’s log file in the PricingPolicy class.” Information can be hidden in the wrong place
  • 29. Values in E Promotes High cohesion Freedom in changing things Clarity Low coupling Testability
  • 30. Resources Design Patterns Explained A New Perspective on Object-Oriented Design Design Patterns Elements of Reusable Object-Oriented Software Code Complete
  • 31. Please fill the evaluation form Thank you very much EigelSilviu-Horea, silviu.eigel@endava.com