SlideShare a Scribd company logo
1 of 34
OO

Tim Mahy
History
• Buzz now but already old (60’s)
• Structured was more populair
OO vs Structured
• Programming - early 60s
  Design - early 70s
  Analysis - late 70s

• SA -> SD -> SP

• Separate data and behavior

• Conceptual canyon between phases

• Difficult to validate back to original analysis
OO vs Structured
• Programming - late 60s
  Design - mid 80s
  Analysis - late 80s

• OOA -> OOD -> OOP

• Incorporate data and behavior

• Smooth transition between phases

• Validation of system back to original analysis
OO vs Structured

• Programming - late 60s      • Programming - early 60s
  Design - mid 80s              Design - early 70s
  Analysis - late 80s           Analysis - late 70s
• OOA -> OOD -> OOP
                              • SA -> SD -> SP
• Incorporate data and
  behavior                    • Separate data and
                                behavior
• Smooth transition
  between phases              • Conceptual canyon
                                between phases
• Validation of system back
  to original analysis
                              • Difficult to validate back
                                to original analysis
Why OO ?
•   Rigid
•   Fragile
•   Not reusable
•   High Viscosity
•   Useless complexity
•   Repetition
•   Opacity
Why OO ? - Rigid
• Difficulties with changes
  – Unforeseen side effects occur frequently
  – Hard to estimate time to complete modifications
• "Roach Motel"
  – Always in need of more effort
• Management reluctant to allow changes
  – Official rigidity, "don't touch a working system"
  – Users forced to develop workarounds
Why OO ? - Fragil
• Small changes have large side effects
  – New bugs appear regularly
  – In the limit of P(bug|change) = 1 system is
    impossible to maintain
• It looks like control has been lost
  – Users become critical
  – Program looses credibility
  – Developers loose credibility
Why OO ? - Not Reusable
• You have a problem and find some piece of
  code which might solve it
  – but it brings in a lot of other stuff
  – it needs changes here and there
• Eventually you have two choices
  – Take over maintainance of the branched code
  – Roll your own
• You would like to include headers and link a
  library maintained by somebody else
Why OO ? – High Viscosity
• Viscosity of the design
  – Hard to make changes properly, i.e. without
    breaking the design → make hacks instead
• Viscosity of the environment
  – Slow and inefficient development environment
  – Large incentive to keep changes localised even if
    they break designs
  – Design changes are very difficult
Why OO ? – Useless Complexity
• Design/code contains useless elements
• Often for anticipated changes or extension
  – May pay off
  – Meanwhile makes design/code harder to
    understand
• Or leftovers of previous design changes?
  – Time for a clean-up
• Trade-off between complexity now and
  anticipated changes later
Why OO ? - Repetition
• Added functionality using cut-and-paste
  – Then slight modifications for local purpose
• Find same structure repeatedly
  – More code
  – Harder to debug and modify
• There is an abstraction somewhere
  – Refactor into function/method
  – Create class(es) to do the job
Why OO ? - Opacity
• Design/code difficult to understand
  – We have all suffered ...
  – What is clear now may seem strange later
• Ok when its your code
  – You suffer in silence
• Not acceptable in collaboration
  – Need to code clearly, may need to rearrange
  – Code reviews?
OO can solve it !
•   Code is less rigid
•   Code is less fragile
•   Reuse is possible
•   Viscosity is low

• When well implemented, OO is not the silver
  bullet !
OO can solve it – Less rigid code
•   Modules can be interchanged
•   Changes are confined to a few modules
•   Cost of changes can be estimated
•   Changes can be planned and scheduled
•   Management is possible
OO can solve it – Less fragile code
• Confined changes mean P(bug|change) is
  small
• New bugs will most likely appear where the
  changes was made, i.e. localised
  – Easier to fix (hopefully)
• Risk of changes can be estimated
• Credibility of code and developers conserved
OO can solve it – Reuse code
• A module can be used in a different context
  without changes
  – Just use headers and link a library
• No need to compile and/or link lots of
  unrelated stuff
OO can solve it – Less viscosity
• Design is easy to modify
  – No quick hacks needed
  – Proper design improvements will actually happen
• Large scale changes affecting many modules
  are possible
  – Reasonable compile and link times for the whole
    system
  – May depend on adequate hardware as well
Yeah right .. show me !
OO is all about ..
•   Objects
•   Classes
•   Inheritance
•   Methods and messages
•   Encapsulation
•   Polymorphism
•   Dynamic binding
Object and classes
• An object is some private data and a set of
  operations that can access that data
• Contains both data (what it knows) and
  behavior (what it can do)
• Attributes: what an object knows (about
  itself)
• Methods: what an object can do
• Instance: a particular object == an object
• Identity: each instance is unique, even if very
  similar
Encapsulation
• Encapsulation means an object’s data (attributes)
  is hidden within, and protected by, a shell of
  procedures (methods)
• Also known as information hiding
• Methods allow for hiding of information by
  concealing the way in which an object satisfies a
  request
• When we send a message, we do not know how
  or where it will be satisfied
• The interface is public; the internals are private
Methods and Messages
• A method is what an object can do; a specific
  implementation of an operation by a
  particular object

• A message is a command by one object/class
  for another object/class to perform an
  operation; it is the communication among
  objects/classes
Inheritance
• A relationship among classes wherein one
  class shares the structure or behavior defined
  in one (single inheritance) or more (multiple
  inheritance) other classes.
• Based on a hierarchical (IS-A) relationship
Polymorphism
• Polymorphism: the same method name can
  elicit a different response depending on the
  receiver
OO can also be shitty written ! Soo.. ?
OO goes beyond classes, objects ..
•   Open-Closed Principle
•   Liskov Substitution Principle
•   Dependency Inversion Principle
•   Interface Segregation Principle
•   Single-Responsibility Principle
•   Design Patterns
Open-Closed Principle
A module (class) should be open for extension but
  closed for modification (originally by Bertrand
  Meyer).
• Classes should be written so that they can be
  extended without requiring modification.
• This allows one to change what a class does
  without changing the class’s source code.
• To extend the behaviour of a system (in response
  to a requested change) add new code, don’t
  modify existing code.
• Abstraction (and subtype polymorphism) are the
  keys to the Open Closed Principle.
Liskov Substitution Principle
Subclasses should be substitutable for their base classes.
  (originally by Barbara Liskov)
• A user of a base class instance should still function if
  given an instance of a derived class instead.
• “A derived class should have some kind of specialized
  behavior (it should provide the same services as the
  superclass, only some, at least, are provided
  differently.)”
• The contract of the base class must be honored by the
  derived class. (See Design by Contract in Lecture 2.)
• If this principle is violated, then it will cause the Open-
  Closed Principle to be violated also. Why?
Dependency Inversion Principle
Depend upon abstractions. Do not depend upon concrete
  implementations (originally defined by Martin).
• High level classes should not depend on low level classes.
• Abstractions should not depend upon the details.
• If the high level abstractions depend on the low level
  implementation details, then the dependency is inverted from what
  it should be.
• High level classes should contain the “business logic”, low level
  classes should contain the details of the (current) implementation.
• Access instances using interfaces or abstract classes to avoid
  dependency inversion.
  If higher levels of the application are not going to depend
  on particular, low level implementations, how does one
  construct the necessary low level implementations?
Interface Segregation Principle
Many client-specific interfaces are better than one general
  purpose interface. (Martin)
• If you have a class with several different uses, create
  separate (narrow) interfaces for each use.
• The alternative is that all uses share the same, large
  interface (and most uses will need only a small number of
  the methods.)
• Instead the uses of the class can be organized as groups of
  related methods, each of which serves a different purpose.
  Each of these groups becomes a separate interface.
• The purpose is to make clients use as small and as coherent
  an interface as possible.
• Fat interfaces lead to inadvertent couplings and accidental
  dependencies between classes.
Single-Responsibility Principle
A class should have only one reason to change
  (originally by Martin).
• A responsibility is “a reason for change.”
• The responsibilities of a class are axes of
  change. If it has two responsibilities, they are
  coupled in the design, and so have to change
  together.
• Simple, yet hard to get right.
• Hint: delegate, delegate, delegate!
Design patterns
• GoF
• Design by contract, not by implementation !
Never let your software smell !

More Related Content

Similar to 2009 training - tim m - object oriented programming

Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1Julie Iskander
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureAttila Bertók
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesYoav Francis
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .NetHariom Shah
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane1
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane2
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patternsRahul Singh
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design PrinciplesSerhiy Oplakanets
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleNoam Kfir
 
2012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp022012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp02rittelfischer
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Arnaud Bouchez
 
The Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot PersistenceThe Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot PersistenceAbdelmonaim Remani
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
Restructuring- improving the modularity of an existing code-base
Restructuring- improving the modularity of an existing code-baseRestructuring- improving the modularity of an existing code-base
Restructuring- improving the modularity of an existing code-baseChris Chedgey
 
Software Design Principles (SOLID)
Software Design Principles (SOLID)Software Design Principles (SOLID)
Software Design Principles (SOLID)ASIMYILDIZ
 

Similar to 2009 training - tim m - object oriented programming (20)

Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean Architecture
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and Practices
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .Net
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
Restructuring
RestructuringRestructuring
Restructuring
 
2012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp022012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp02
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
 
The Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot PersistenceThe Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot Persistence
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Restructuring- improving the modularity of an existing code-base
Restructuring- improving the modularity of an existing code-baseRestructuring- improving the modularity of an existing code-base
Restructuring- improving the modularity of an existing code-base
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
Software Design Principles (SOLID)
Software Design Principles (SOLID)Software Design Principles (SOLID)
Software Design Principles (SOLID)
 

More from Tim Mahy

2013 training - tim m - cross cutting concerns
2013   training - tim m - cross cutting concerns2013   training - tim m - cross cutting concerns
2013 training - tim m - cross cutting concernsTim Mahy
 
2009 seminar - tim m - vs 2010 developer edition
2009   seminar - tim m - vs 2010 developer edition2009   seminar - tim m - vs 2010 developer edition
2009 seminar - tim m - vs 2010 developer editionTim Mahy
 
2010 iska - tim m - functioneel programmeren in c-sharp
2010   iska - tim m - functioneel programmeren in c-sharp2010   iska - tim m - functioneel programmeren in c-sharp
2010 iska - tim m - functioneel programmeren in c-sharpTim Mahy
 
2010 iska - tim m - nosql iska
2010   iska - tim m - nosql iska2010   iska - tim m - nosql iska
2010 iska - tim m - nosql iskaTim Mahy
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven designTim Mahy
 
2012 student track - vs2010
2012   student track - vs20102012   student track - vs2010
2012 student track - vs2010Tim Mahy
 
communityday 2012 - cqrs
communityday 2012 - cqrscommunityday 2012 - cqrs
communityday 2012 - cqrsTim Mahy
 
CQRS & Queue unlimited
CQRS & Queue unlimitedCQRS & Queue unlimited
CQRS & Queue unlimitedTim Mahy
 

More from Tim Mahy (8)

2013 training - tim m - cross cutting concerns
2013   training - tim m - cross cutting concerns2013   training - tim m - cross cutting concerns
2013 training - tim m - cross cutting concerns
 
2009 seminar - tim m - vs 2010 developer edition
2009   seminar - tim m - vs 2010 developer edition2009   seminar - tim m - vs 2010 developer edition
2009 seminar - tim m - vs 2010 developer edition
 
2010 iska - tim m - functioneel programmeren in c-sharp
2010   iska - tim m - functioneel programmeren in c-sharp2010   iska - tim m - functioneel programmeren in c-sharp
2010 iska - tim m - functioneel programmeren in c-sharp
 
2010 iska - tim m - nosql iska
2010   iska - tim m - nosql iska2010   iska - tim m - nosql iska
2010 iska - tim m - nosql iska
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven design
 
2012 student track - vs2010
2012   student track - vs20102012   student track - vs2010
2012 student track - vs2010
 
communityday 2012 - cqrs
communityday 2012 - cqrscommunityday 2012 - cqrs
communityday 2012 - cqrs
 
CQRS & Queue unlimited
CQRS & Queue unlimitedCQRS & Queue unlimited
CQRS & Queue unlimited
 

Recently uploaded

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[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
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[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
 

2009 training - tim m - object oriented programming

  • 2. History • Buzz now but already old (60’s) • Structured was more populair
  • 3. OO vs Structured • Programming - early 60s Design - early 70s Analysis - late 70s • SA -> SD -> SP • Separate data and behavior • Conceptual canyon between phases • Difficult to validate back to original analysis
  • 4. OO vs Structured • Programming - late 60s Design - mid 80s Analysis - late 80s • OOA -> OOD -> OOP • Incorporate data and behavior • Smooth transition between phases • Validation of system back to original analysis
  • 5. OO vs Structured • Programming - late 60s • Programming - early 60s Design - mid 80s Design - early 70s Analysis - late 80s Analysis - late 70s • OOA -> OOD -> OOP • SA -> SD -> SP • Incorporate data and behavior • Separate data and behavior • Smooth transition between phases • Conceptual canyon between phases • Validation of system back to original analysis • Difficult to validate back to original analysis
  • 6. Why OO ? • Rigid • Fragile • Not reusable • High Viscosity • Useless complexity • Repetition • Opacity
  • 7. Why OO ? - Rigid • Difficulties with changes – Unforeseen side effects occur frequently – Hard to estimate time to complete modifications • "Roach Motel" – Always in need of more effort • Management reluctant to allow changes – Official rigidity, "don't touch a working system" – Users forced to develop workarounds
  • 8. Why OO ? - Fragil • Small changes have large side effects – New bugs appear regularly – In the limit of P(bug|change) = 1 system is impossible to maintain • It looks like control has been lost – Users become critical – Program looses credibility – Developers loose credibility
  • 9. Why OO ? - Not Reusable • You have a problem and find some piece of code which might solve it – but it brings in a lot of other stuff – it needs changes here and there • Eventually you have two choices – Take over maintainance of the branched code – Roll your own • You would like to include headers and link a library maintained by somebody else
  • 10. Why OO ? – High Viscosity • Viscosity of the design – Hard to make changes properly, i.e. without breaking the design → make hacks instead • Viscosity of the environment – Slow and inefficient development environment – Large incentive to keep changes localised even if they break designs – Design changes are very difficult
  • 11. Why OO ? – Useless Complexity • Design/code contains useless elements • Often for anticipated changes or extension – May pay off – Meanwhile makes design/code harder to understand • Or leftovers of previous design changes? – Time for a clean-up • Trade-off between complexity now and anticipated changes later
  • 12. Why OO ? - Repetition • Added functionality using cut-and-paste – Then slight modifications for local purpose • Find same structure repeatedly – More code – Harder to debug and modify • There is an abstraction somewhere – Refactor into function/method – Create class(es) to do the job
  • 13. Why OO ? - Opacity • Design/code difficult to understand – We have all suffered ... – What is clear now may seem strange later • Ok when its your code – You suffer in silence • Not acceptable in collaboration – Need to code clearly, may need to rearrange – Code reviews?
  • 14. OO can solve it ! • Code is less rigid • Code is less fragile • Reuse is possible • Viscosity is low • When well implemented, OO is not the silver bullet !
  • 15. OO can solve it – Less rigid code • Modules can be interchanged • Changes are confined to a few modules • Cost of changes can be estimated • Changes can be planned and scheduled • Management is possible
  • 16. OO can solve it – Less fragile code • Confined changes mean P(bug|change) is small • New bugs will most likely appear where the changes was made, i.e. localised – Easier to fix (hopefully) • Risk of changes can be estimated • Credibility of code and developers conserved
  • 17. OO can solve it – Reuse code • A module can be used in a different context without changes – Just use headers and link a library • No need to compile and/or link lots of unrelated stuff
  • 18. OO can solve it – Less viscosity • Design is easy to modify – No quick hacks needed – Proper design improvements will actually happen • Large scale changes affecting many modules are possible – Reasonable compile and link times for the whole system – May depend on adequate hardware as well
  • 19. Yeah right .. show me !
  • 20. OO is all about .. • Objects • Classes • Inheritance • Methods and messages • Encapsulation • Polymorphism • Dynamic binding
  • 21. Object and classes • An object is some private data and a set of operations that can access that data • Contains both data (what it knows) and behavior (what it can do) • Attributes: what an object knows (about itself) • Methods: what an object can do • Instance: a particular object == an object • Identity: each instance is unique, even if very similar
  • 22. Encapsulation • Encapsulation means an object’s data (attributes) is hidden within, and protected by, a shell of procedures (methods) • Also known as information hiding • Methods allow for hiding of information by concealing the way in which an object satisfies a request • When we send a message, we do not know how or where it will be satisfied • The interface is public; the internals are private
  • 23. Methods and Messages • A method is what an object can do; a specific implementation of an operation by a particular object • A message is a command by one object/class for another object/class to perform an operation; it is the communication among objects/classes
  • 24. Inheritance • A relationship among classes wherein one class shares the structure or behavior defined in one (single inheritance) or more (multiple inheritance) other classes. • Based on a hierarchical (IS-A) relationship
  • 25. Polymorphism • Polymorphism: the same method name can elicit a different response depending on the receiver
  • 26. OO can also be shitty written ! Soo.. ?
  • 27. OO goes beyond classes, objects .. • Open-Closed Principle • Liskov Substitution Principle • Dependency Inversion Principle • Interface Segregation Principle • Single-Responsibility Principle • Design Patterns
  • 28. Open-Closed Principle A module (class) should be open for extension but closed for modification (originally by Bertrand Meyer). • Classes should be written so that they can be extended without requiring modification. • This allows one to change what a class does without changing the class’s source code. • To extend the behaviour of a system (in response to a requested change) add new code, don’t modify existing code. • Abstraction (and subtype polymorphism) are the keys to the Open Closed Principle.
  • 29. Liskov Substitution Principle Subclasses should be substitutable for their base classes. (originally by Barbara Liskov) • A user of a base class instance should still function if given an instance of a derived class instead. • “A derived class should have some kind of specialized behavior (it should provide the same services as the superclass, only some, at least, are provided differently.)” • The contract of the base class must be honored by the derived class. (See Design by Contract in Lecture 2.) • If this principle is violated, then it will cause the Open- Closed Principle to be violated also. Why?
  • 30. Dependency Inversion Principle Depend upon abstractions. Do not depend upon concrete implementations (originally defined by Martin). • High level classes should not depend on low level classes. • Abstractions should not depend upon the details. • If the high level abstractions depend on the low level implementation details, then the dependency is inverted from what it should be. • High level classes should contain the “business logic”, low level classes should contain the details of the (current) implementation. • Access instances using interfaces or abstract classes to avoid dependency inversion. If higher levels of the application are not going to depend on particular, low level implementations, how does one construct the necessary low level implementations?
  • 31. Interface Segregation Principle Many client-specific interfaces are better than one general purpose interface. (Martin) • If you have a class with several different uses, create separate (narrow) interfaces for each use. • The alternative is that all uses share the same, large interface (and most uses will need only a small number of the methods.) • Instead the uses of the class can be organized as groups of related methods, each of which serves a different purpose. Each of these groups becomes a separate interface. • The purpose is to make clients use as small and as coherent an interface as possible. • Fat interfaces lead to inadvertent couplings and accidental dependencies between classes.
  • 32. Single-Responsibility Principle A class should have only one reason to change (originally by Martin). • A responsibility is “a reason for change.” • The responsibilities of a class are axes of change. If it has two responsibilities, they are coupled in the design, and so have to change together. • Simple, yet hard to get right. • Hint: delegate, delegate, delegate!
  • 33. Design patterns • GoF • Design by contract, not by implementation !
  • 34. Never let your software smell !