Code like a ninja session 1 object-oriented principles
-
Upload
deon-meyer -
Category
Technology
-
view
160 -
download
0
description
Transcript of Code like a ninja session 1 object-oriented principles
CODE LIKE A NINJASESSION 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: OOPrinciples\Encapsulation]
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: OOPrinciples\Abstraction]
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: OOPrinciples\Inheritance]
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: OOPrinciples\Polymorphism]
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