SlideShare a Scribd company logo
1 of 16
CODE LIKE A NINJA
SESSION 1 - INTRODUCTION TO OBJECT-ORIENTATION
SESSION RESOURCES
• Presentation session notes including link to this session, will be
available on http://learningaboutfudge.blogspot.com
• All the source for this session is publically available at:
https://github.com/SheepWorx/Training
• Source was compiled using Visual Studio 2012
WHY DO WE NEED TO KNOW THIS?
• Dependency Management is an issue that most of us have faced.
• Poor dependency management leads to code that is hard to
change, fragile, and non-reusable.
• When dependencies are well managed, the code remains
flexible, robust, and reusable.
- Robert C Martin (father of OOD)
WHAT WE WISH TO ACHIEVE
The aim to write code that is
• Testable
• Reusable
• Extensible
• Maintainable
• Less buggy
PRIMARY PRINCIPLES
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism
• Decoupling
ENCAPSULATION
Definition: the hiding of non-essential features
Laymen’s terms: making something Public, Protected, Internal,
Protected Internal or Private
[Code: OOPrinciplesEncapsulation]
ENCAPSULATION (CONT)
• Public : Access is not restricted.
• Protected : Access is limited to the containing class or types derived
from the containing class.
• Internal: Access is limited to the current assembly.
• Protected Internal: Access is limited to the current assembly or types
derived from the containing class.
• Private : Access is limited to the containing type.
ABSTRACTION
Definition: To only represent essential features of an object.
Definition 2: To reduce and factor out details so that once can focus on
a few concepts at a time
Laymen’s terms: Reduce code redundancy and enable code reuse.
[Code: OOPrinciplesAbstraction]
INHERITANCE
Definition: a Mechanism to enable code reuse by abstracting code to
subclasses or defining standard signatures using interfaces
Laymen’s terms: Creating child-parent relationship between classes
using normal classes, abstract classes or interfaces
INHERITANCE (CONT)
[Code: OOPrinciplesInheritance]
Before After
POLYMORPHISM
Definition: the provision of a single interface to entities of different types
Laymen’s terms: Abstracting common functionality to a parent class and
then creating child classes by inheriting the parent class, inheriting any
accessible methods and properties along with it
POLYMORPHISM (CONT)
[Code: OOPrinciplesPolymorphism]
DECOUPLING
Definition: disconnecting an abstraction from its implementation so that
the two can vary independently
Laymen’s terms: Introducing a potato-class. If class1 and class2 are
tightly-coupled by the one instantiating the other, to split off the
dependency by introducing a 3rd class, usually in the form of an
interface.
DECOUPLING (CONT)
DECOUPLING (CONT)
WHAT’S NEXT
Topic: S.O.L.ID – The Single Responsibility Principle
Where: 14:00-15:00 @ W4

More Related Content

Similar to Code like a ninja session 1 object-oriented principles

The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptBill Buchan
 
Code like a ninja session 3 open-closed principle
Code like a ninja  session 3   open-closed principleCode like a ninja  session 3   open-closed principle
Code like a ninja session 3 open-closed principleDeon Meyer
 
Dependency injection via annotations v1.0
Dependency injection via annotations v1.0Dependency injection via annotations v1.0
Dependency injection via annotations v1.0Jerry Kurian
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxhreempandya
 
Features of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptxFeatures of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptxSwagatoBiswas
 
Lesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptxLesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptxLuiFlor
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Adair Dingle
 
What are some key topics and concepts that candidates are commonly expected t...
What are some key topics and concepts that candidates are commonly expected t...What are some key topics and concepts that candidates are commonly expected t...
What are some key topics and concepts that candidates are commonly expected t...DivyanshWsCube
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.Questpond
 
Functional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakFunctional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakSigma Software
 
Turbo Charging Moodle
Turbo Charging MoodleTurbo Charging Moodle
Turbo Charging MoodleJulian Ridden
 
520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdf520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdfAniruddhNain1
 
U1 JAVA.pptx
U1 JAVA.pptxU1 JAVA.pptx
U1 JAVA.pptxmadan r
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programmingAmar Jukuntla
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principlesdeonpmeyer
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1Julie Iskander
 

Similar to Code like a ninja session 1 object-oriented principles (20)

The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
Code like a ninja session 3 open-closed principle
Code like a ninja  session 3   open-closed principleCode like a ninja  session 3   open-closed principle
Code like a ninja session 3 open-closed principle
 
Dependency injection via annotations v1.0
Dependency injection via annotations v1.0Dependency injection via annotations v1.0
Dependency injection via annotations v1.0
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptx
 
Features of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptxFeatures of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptx
 
Lesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptxLesson 1 - Object Oriented Programming CPP103.pptx
Lesson 1 - Object Oriented Programming CPP103.pptx
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
 
What are some key topics and concepts that candidates are commonly expected t...
What are some key topics and concepts that candidates are commonly expected t...What are some key topics and concepts that candidates are commonly expected t...
What are some key topics and concepts that candidates are commonly expected t...
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
oop.pptx
oop.pptxoop.pptx
oop.pptx
 
Functional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakFunctional Solid, Aleksandr Sugak
Functional Solid, Aleksandr Sugak
 
Functional solid
Functional solidFunctional solid
Functional solid
 
General oop concept
General oop conceptGeneral oop concept
General oop concept
 
android principle.pptx
android principle.pptxandroid principle.pptx
android principle.pptx
 
Turbo Charging Moodle
Turbo Charging MoodleTurbo Charging Moodle
Turbo Charging Moodle
 
520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdf520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdf
 
U1 JAVA.pptx
U1 JAVA.pptxU1 JAVA.pptx
U1 JAVA.pptx
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 

Recently uploaded

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
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 

Recently uploaded (20)

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
 
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...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 

Code like a ninja session 1 object-oriented principles

  • 1. CODE LIKE A NINJA SESSION 1 - INTRODUCTION TO OBJECT-ORIENTATION
  • 2. SESSION RESOURCES • Presentation session notes including link to this session, will be available on http://learningaboutfudge.blogspot.com • All the source for this session is publically available at: https://github.com/SheepWorx/Training • Source was compiled using Visual Studio 2012
  • 3. WHY DO WE NEED TO KNOW THIS? • Dependency Management is an issue that most of us have faced. • Poor dependency management leads to code that is hard to change, fragile, and non-reusable. • When dependencies are well managed, the code remains flexible, robust, and reusable. - Robert C Martin (father of OOD)
  • 4. WHAT WE WISH TO ACHIEVE The aim to write code that is • Testable • Reusable • Extensible • Maintainable • Less buggy
  • 5. PRIMARY PRINCIPLES • Encapsulation • Abstraction • Inheritance • Polymorphism • Decoupling
  • 6. ENCAPSULATION Definition: the hiding of non-essential features Laymen’s terms: making something Public, Protected, Internal, Protected Internal or Private [Code: OOPrinciplesEncapsulation]
  • 7. ENCAPSULATION (CONT) • Public : Access is not restricted. • Protected : Access is limited to the containing class or types derived from the containing class. • Internal: Access is limited to the current assembly. • Protected Internal: Access is limited to the current assembly or types derived from the containing class. • Private : Access is limited to the containing type.
  • 8. ABSTRACTION Definition: To only represent essential features of an object. Definition 2: To reduce and factor out details so that once can focus on a few concepts at a time Laymen’s terms: Reduce code redundancy and enable code reuse. [Code: OOPrinciplesAbstraction]
  • 9. INHERITANCE Definition: a Mechanism to enable code reuse by abstracting code to subclasses or defining standard signatures using interfaces Laymen’s terms: Creating child-parent relationship between classes using normal classes, abstract classes or interfaces
  • 11. POLYMORPHISM Definition: the provision of a single interface to entities of different types Laymen’s terms: Abstracting common functionality to a parent class and then creating child classes by inheriting the parent class, inheriting any accessible methods and properties along with it
  • 13. DECOUPLING Definition: disconnecting an abstraction from its implementation so that the two can vary independently Laymen’s terms: Introducing a potato-class. If class1 and class2 are tightly-coupled by the one instantiating the other, to split off the dependency by introducing a 3rd class, usually in the form of an interface.
  • 16. WHAT’S NEXT Topic: S.O.L.ID – The Single Responsibility Principle Where: 14:00-15:00 @ W4

Editor's Notes

  1. Quick questionA popular question: What is Object-Orientation?Can anyone answer?
  2. With encapsulation, you want to restrict access to various values or state.For ex, the most basic example is changing a property from public to private.Why do we want to do this? By limiting outside access to local variables of a class, for ex, you can exert more control over the applications behaviour, which should result in fewer bugs or at least, localized bugs.Demo Example
  3. Abstraction and encapsulation go hand in hand and I see them both as one. In most cases where you’re encapsulating something, you’re also abstracting it.
  4. This is also a form of polymorphism, which we will discuss in the next slide
  5. Here we see that both Airtime and AccountPayment classes are tightly coupled to both basket and product controllerThis is a bad idea because, if we want to introduce a new class, for ex, Traffic fines, we’ll need to update both basket and Product controller as wellAlso, there is the possibility that a change in signature in either airtime or accountpayment, may have an affect on Productcontroller and basket.Lets assume that we want to test Basket in isolation, how will we go about decoupling it from the product controller?
  6. Now we can test both productcontroller or basket in isolation.