আগামী ৩০ অক্টোবর -২০১৭ তারিখ থেকে শুরু হচ্ছে পাঁচ মাস ব্যাপী Professional Web Design and Development with HTML,CSS,Bootstrap,PHP,MySQl, AJAX and JQUERY কোর্সের ৮৬ তম ব্যাচ। আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করতে অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল: 01722817591, Email : [email protected] কোর্সের সিলেবাস এর জন্য এখানে ক্লিক করুন ।

Introduction to PHP Design Patterns

Introduction to PHP Design Patterns

Introduction to PHP Design Pattern

What are Design Patterns?

  • Solution to common development problems
  • Reusable successful design and architectures
  • Common language for developers

What Design Patterns are not?

  • The panacea for solving all development problems
  • Ready to use code scripts
  • Cut & Paste solutions

Why Design Patterns?

  • Help you to reuse successful design and architectures
  • Help you to choose design alternatives
  • Help you to solve problems you haven’t seen before
  • Give a common vocabulary
  • Let you communicate quickly and unambiguously
  • Make a system more reusable

One of those magical performance cum code reduction issues is “Design Pattern” which was introduced by Eric Gamma and his three other friends in the book Design Patterns in 1972. Because of four authors, the book was introduced as written by Gang of Four or simply Goff. In that legendary book, Gang of Four introduced several patterns to minimize the amount of code as well as to introduce effective coding practice. In this chapter we will learn some of those patterns to implement in PHP.

The Gang of Four

  1. Erich Gamma
  2. Richard Helm
  3. Ralph Johnson
  4. John Vlissides

Essential Elements

Pattern name: A descriptive name for the pattern, in a word or two

Problem: Describes the problem the pattern applies to

Solution:

¨       Describes the elements and the resources along with their relationship and responsibilities for solving the problem.

¨       This is just an abstract description; the implementation varies according to the programming language

Consequences: Results and trade-off

 Golden Rules

  1. Program to an interface, not an implementation
  2. Some languages takes this rule to the next level with Duck Typing
  3. Favor Object Composition over Inheritance
  4. Black Box approach
  5. Delegate

 How to Select a Design Pattern

  • Consider how to design patterns solve design problems
  • Scan Intent section
  • Study how patterns interrelate
  • Study patterns of like purpose
  • Examine a cause of redesign
  • Consider what should be variable in your design

How to Use a Design Pattern

  • Read the pattern once through for an overview
  • Go back and study the Structure, Participants and Collaboration sections
  • Look at the Sample Code section to see a concrete example of the pattern in code
  • Choose names for pattern participants that are meaningful in the application context
  • Define the classes
  • Define application-specific names for operations in the pattern
  • Implement the operations to carry out the responsibilities and collaborations in the patterns

How to NOT Use a Design Pattern

  • Don’t try to rewrite your application to fit a Design Pattern, select the best Pattern according to your needs
  • Don’t use a Design Pattern because it’s cool… use a Pattern because you need it
  • Don’t copy/paste language-specific Pattern implementations, understand how the Pattern works and how you can implement it in your application

Frameworks vs Design Patterns

  • Design patterns are more abstract than frameworks
  • Design patterns are smaller architectural elements than frameworks
  • Design patterns are less specialized than frameworks
  • A typical framework contains several design patterns, but the reverse is never true

Design Pattern Classification

Design Patterns by Purpose

  • Creational Patterns

Concern the process of object creation

  • Structural Patterns

Deal with the composition of object and classes

  • Behavioral Patterns

Characterize the way in which classes or objects interact

  • Concurrency Patterns
  • Architectural Patterns

 …

 

Design Patterns by Scope

Class Patterns

  • Deal with relationships between classes and their subclasses.

Ex. Factory Method, Adapter, Template method…

Object Patterns

  • Deal with object relationships.
  • The most part of patterns are in the object scope.

Ex. Singleton, Adapter, Decorator, Proxy, Iterator, Observer…

 

Design Patterns

Architectural

  • MVC

Creational

  • Singleton
  • Factory Method
  • Lazy initialization

Structural

  • Adapter
  • Proxy

Behavioral

  • Iterator
  • Observer
  • Strategy
  • Template Method

More

  • Registry
  • Mock Object

  Design Patterns in Action

Pattern Template

  • Problem & Solution
  • Considerations
  • In pictures
  • Implementation & Examples
  • In the Wild
  • Using and Abusing
Hi, My name is Masud Alam, love to work with Open Source Technologies, living in Dhaka, Bangladesh. I graduated in 2009 with a bachelor's degree in Engineering from State University Of Bangladesh, I'm also a Certified Engineer on ZEND PHP 5.3, I served my first five years a number of leadership positions at Winux Soft Ltd, SSL Wireless Ltd, CIDA and MAX Group where I worked on ERP software and web development., but now i'm a co-founder and Chief Executive Officer and Managing Director of TechBeeo Software Consultancy Services Ltd. I'm also a Course Instructor of ZCPE PHP 7 Certification and professional web development course at w3programmers Training Institute - a leading Training Institute in the country.
3 comments on “Introduction to PHP Design Patterns
  1. Hi,
    Would you like to add some code to demonstrate where/how and which to use design patterns? Like processing orders (shop), validating forms/input data, fascade for complex system with multiple models/tables….?

Leave a Reply

Your email address will not be published. Required fields are marked *