Object-oriented programming
Design Patterns
Beer & Code #49
JUN
16
@talevskiigor
Object-oriented programming
If you want to program just about anything these days,
you’d better learn object-oriented programming.
Anyone should write a framework and never use it !
Who cares, right? We have the framework! We don't need to
know how to "do it by hand"! Right?
OOP: Basic
Attribute - things that the object stores data in, generally variables
Method - Functions and Procedures attached to an Object and allowing the
object to perform actions
Class - a class is a template definition of the methods and variables in a
particular kind of object
Object - is a specific instance of a class; it contains real values instead of
variables
OOP: Visibility
Public
- can be accessed everywhere
Protected
- can be accessed only within the class itself and by inherited classes
Private
- may only be accessed by the class that defines the member
Access modifiers (or access specifiers) are keywords in object-oriented languages that set the
accessibility of classes, methods, and other members
OOP: What is a design pattern?
In software engineering, a design pattern is a general repeatable solution to a
commonly occurring problem in software design.
A design pattern isn't a finished design that can be transformed directly into
code.
It is a description or template for how to solve a problem that can be used in
many different situations.
Design Patterns: History
Patterns originated as an architectural concept by Christopher Alexander (1977).
In 1994, four authors Erich G., Richard H., Ralph J. and John V. published a book
Design Patterns - Elements of Reusable Object-Oriented Software.
These authors are collectively known as Gang of Four (GOF). According to these
authors design patterns are primarily based on the following principles of object
orientated design.
Program to an interface not an implementation
Favor object composition over inheritance
Design Patterns: Types
Creational Patterns - These design patterns provide a way to create objects
while hiding the creation logic, rather than instantiating objects directly using
new operator. This gives program more flexibility in deciding which objects
need to be created for a given use case.
Structural Patterns - These design patterns concern class and object
composition. Concept of inheritance is used to compose interfaces and define
ways to compose objects to obtain new functionalities.
Behavioral Patterns - These design patterns are specifically concerned with
communication between objects.
Creational Patterns
Abstract factory create series of related or dependent objects without
specifying their concrete classes. Usually the created classes all implement
the same interface
Static factory uses just one static method to create all types of objects it can
create. It is usually named factory or build
Factory method pattern creates objects without specifying the exact class to
create.
Builder pattern constructs complex objects by separating construction and
representation.
Prototype pattern creates objects by cloning an existing object.
Singleton pattern restricts object creation for a class to only one instance.
Structural Patterns (1 of 2)
Adapter / Wrapper - translate one interface for a class into a compatible interface
Bridge - Decouple an abstraction from its implementation so that the two can vary
independently.
Composite - treat a group of objects the same way as a single instance of the
object
Data Mapper - performs bidirectional transfer of data between a persistent data
store (database) and an in memory data representation (domain).
Decorator - allows behavior to be added to an individual object without affecting
the behavior of other objects from the same class
Dependency Injection - implement a loosely coupled architecture in order to get
better testable, maintainable and extendable code.
Structural Patterns (2 of 2)
Facade - provides a simplified interface to a larger body of code, such as a
class library.
Fluent Interface - write code that is easy readable just like sentences in a
natural language (like English).
Flyweight - instances of a class which are identical are shared in an
implementation instead of creating a new instance of that class for every
instance
Proxy - one class stands in for and handles all access to another class
Registry(Service locator pattern) - implement a central storage for objects often
used throughout the application, is typically implemented using an abstract
class with only static methods (or using the Singleton pattern)
Behavioral Patterns (1 of 2)
Chain Of Responsibilities - build a chain of objects to handle a call in
sequential order.
Command - an object is used to encapsulate all information needed to perform
an action or trigger an event at a later time
Iterator - make an object iterable and to make it appear like a collection of
objects
Mediator - easy way to decouple many components working together
Memento - provides the ability to restore an object to it’s previous state (undo
via rollback) or to gain access to state of the object, without revealing it’s
implementation
Null Object - not a GoF design pattern but a schema which appears frequently
enough to be considered a pattern
Behavioral Patterns (2 of 2)
Observer - implement a publish/subscribe behaviour to an object, whenever a
“Subject” object changes it’s state, the attached “Observers” will be notified
Specification - separate the statement of how to match a candidate, from the
candidate object that it is matched against
State - implements a state machine in an object-oriented way
Visitor - lets you outsource operations on objects to other objects
Strategy - separate strategies and to enable fast switching between them
Template Method - one or more algorithm steps can be overridden by
subclasses to allow differing behaviors while ensuring that the overarching
algorithm is still followed
Live coding!
What can go wrong? ;-)
Tuesday, June 21 at 6 PM - 8 PM
All you wanted to know about JavaScript, but were afraid to ask...

OOP design patterns

  • 1.
    Object-oriented programming Design Patterns Beer& Code #49 JUN 16 @talevskiigor
  • 2.
    Object-oriented programming If youwant to program just about anything these days, you’d better learn object-oriented programming. Anyone should write a framework and never use it ! Who cares, right? We have the framework! We don't need to know how to "do it by hand"! Right?
  • 3.
    OOP: Basic Attribute -things that the object stores data in, generally variables Method - Functions and Procedures attached to an Object and allowing the object to perform actions Class - a class is a template definition of the methods and variables in a particular kind of object Object - is a specific instance of a class; it contains real values instead of variables
  • 4.
    OOP: Visibility Public - canbe accessed everywhere Protected - can be accessed only within the class itself and by inherited classes Private - may only be accessed by the class that defines the member Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members
  • 5.
    OOP: What isa design pattern? In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.
  • 6.
    Design Patterns: History Patternsoriginated as an architectural concept by Christopher Alexander (1977). In 1994, four authors Erich G., Richard H., Ralph J. and John V. published a book Design Patterns - Elements of Reusable Object-Oriented Software. These authors are collectively known as Gang of Four (GOF). According to these authors design patterns are primarily based on the following principles of object orientated design. Program to an interface not an implementation Favor object composition over inheritance
  • 7.
    Design Patterns: Types CreationalPatterns - These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This gives program more flexibility in deciding which objects need to be created for a given use case. Structural Patterns - These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities. Behavioral Patterns - These design patterns are specifically concerned with communication between objects.
  • 8.
    Creational Patterns Abstract factorycreate series of related or dependent objects without specifying their concrete classes. Usually the created classes all implement the same interface Static factory uses just one static method to create all types of objects it can create. It is usually named factory or build Factory method pattern creates objects without specifying the exact class to create. Builder pattern constructs complex objects by separating construction and representation. Prototype pattern creates objects by cloning an existing object. Singleton pattern restricts object creation for a class to only one instance.
  • 9.
    Structural Patterns (1of 2) Adapter / Wrapper - translate one interface for a class into a compatible interface Bridge - Decouple an abstraction from its implementation so that the two can vary independently. Composite - treat a group of objects the same way as a single instance of the object Data Mapper - performs bidirectional transfer of data between a persistent data store (database) and an in memory data representation (domain). Decorator - allows behavior to be added to an individual object without affecting the behavior of other objects from the same class Dependency Injection - implement a loosely coupled architecture in order to get better testable, maintainable and extendable code.
  • 10.
    Structural Patterns (2of 2) Facade - provides a simplified interface to a larger body of code, such as a class library. Fluent Interface - write code that is easy readable just like sentences in a natural language (like English). Flyweight - instances of a class which are identical are shared in an implementation instead of creating a new instance of that class for every instance Proxy - one class stands in for and handles all access to another class Registry(Service locator pattern) - implement a central storage for objects often used throughout the application, is typically implemented using an abstract class with only static methods (or using the Singleton pattern)
  • 11.
    Behavioral Patterns (1of 2) Chain Of Responsibilities - build a chain of objects to handle a call in sequential order. Command - an object is used to encapsulate all information needed to perform an action or trigger an event at a later time Iterator - make an object iterable and to make it appear like a collection of objects Mediator - easy way to decouple many components working together Memento - provides the ability to restore an object to it’s previous state (undo via rollback) or to gain access to state of the object, without revealing it’s implementation Null Object - not a GoF design pattern but a schema which appears frequently enough to be considered a pattern
  • 12.
    Behavioral Patterns (2of 2) Observer - implement a publish/subscribe behaviour to an object, whenever a “Subject” object changes it’s state, the attached “Observers” will be notified Specification - separate the statement of how to match a candidate, from the candidate object that it is matched against State - implements a state machine in an object-oriented way Visitor - lets you outsource operations on objects to other objects Strategy - separate strategies and to enable fast switching between them Template Method - one or more algorithm steps can be overridden by subclasses to allow differing behaviors while ensuring that the overarching algorithm is still followed
  • 13.
    Live coding! What cango wrong? ;-)
  • 14.
    Tuesday, June 21at 6 PM - 8 PM All you wanted to know about JavaScript, but were afraid to ask...