Session 1/8 on Object Orientation, SOLID and Design Patterns. Code can be found at: https://github.com/SheepWorx/Training
1 of 16
Downloaded 14 times
More Related Content
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
6. ENCAPSULATION
Definition: the hiding of non-essential features
Laymens 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
Laymens 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
Laymens 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
Laymens 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
Laymens 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.
#2: Quick questionA popular question: What is Object-Orientation?Can anyone answer?
#7: 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
#9: Abstraction and encapsulation go hand in hand and I see them both as one. In most cases where youre encapsulating something, youre also abstracting it.
#11: This is also a form of polymorphism, which we will discuss in the next slide
#15: 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, well 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?
#16: Now we can test both productcontroller or basket in isolation.