code like a ninja session 1 object-oriented principles
DESCRIPTION
Session 1/8 on Object Orientation, SOLID and Design Patterns. Code can be found at: https://github.com/SheepWorx/TrainingTRANSCRIPT
![Page 1: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/1.jpg)
CODE LIKE A NINJASESSION 1 - INTRODUCTION TO OBJECT-ORIENTATION
![Page 2: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/2.jpg)
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
![Page 3: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/3.jpg)
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)
![Page 4: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/4.jpg)
WHAT WE WISH TO ACHIEVE
The aim to write code that is
• Testable
• Reusable
• Extensible
• Maintainable
• Less buggy
![Page 5: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/5.jpg)
PRIMARY PRINCIPLES
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism
• Decoupling
![Page 6: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/6.jpg)
ENCAPSULATION
Definition: the hiding of non-essential features
Laymen’s terms: making something Public, Protected, Internal, Protected Internal or Private
[Code: OOPrinciples\Encapsulation]
![Page 7: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/7.jpg)
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.
![Page 8: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/8.jpg)
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: OOPrinciples\Abstraction]
![Page 9: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/9.jpg)
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
![Page 10: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/10.jpg)
INHERITANCE (CONT)
[Code: OOPrinciples\Inheritance]
Before After
![Page 11: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/11.jpg)
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
![Page 12: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/12.jpg)
POLYMORPHISM (CONT)
[Code: OOPrinciples\Polymorphism]
![Page 13: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/13.jpg)
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.
![Page 14: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/14.jpg)
DECOUPLING (CONT)
![Page 15: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/15.jpg)
DECOUPLING (CONT)
![Page 16: Code like a ninja session 1 object-oriented principles](https://reader035.vdocuments.us/reader035/viewer/2022070302/546fe5c3af7959a5308b4575/html5/thumbnails/16.jpg)
WHAT’S NEXT
Topic: S.O.L.ID – The Single Responsibility Principle
Where: 14:00-15:00 @ W4