filmov
tv
Decorator - Design Pattern in PHP | OOP Design Patterns | What and How to use it?

Показать описание
Welcome all youtubers who watching this episode. My name Andrii and representing channel MLA Automation. Who is first time hit please on Subscribe button, and Like button. On this channel you will be able to find awesome topics in programming. Currently we are learning PHP and today's episode related to serious of video about Design Patterns in PHP. ..
This time on our consideration in this lesson - Decorator
Analogy
Let's say you have your own car service that provides various services. How do I invoice clients? Add consistently services and their cost - and in the end you will get the total amount to be paid. Here, each type of service is a "decorator".
In a nutshell
The "Decorator" pattern allows dynamic behavior of an object at runtime by wrapping it in an object of the "decorator" class.
Wikipedia
The Decorator pattern allows you to connect additional behavior (statically or dynamically) to an object without affecting the behavior of other objects of the same class. The pattern is often used to adhere to the principle of single responsibility (the principle of single responsibility), as it allows you to divide functionality between classes to solve specific problems.
Example
Link on the Code for Example(above):
What the difference composite vs decorator pattern?
The composite pattern allows you to build a hierarchical structure (such as a tree of elements) in a way that allows your external code to view the entire structure as a single entity. So the interface to a leaf entity is exactly the same as the entity for a compound entity. So the essence is that all elements in your composite structure have the same interface even though some are leaf nodes and others are entire structures. User interfaces often use this approach to allow easy composability.
The decorator pattern allows an entity to completely contain another entity so that using the decorator looks identical to the contained entity. This allows the decorator to modify the behaviour and/or content of whatever it is encapsulating without changing the outward appearance of the entity. For example, you might use a decorator to add logging output on the usage of the contained element without changing any behaviour of the contained element.
Decorator vs Adapter
Decorator, attach additional responsibilities to an object dynamically. For example adding sugar in a coffee.
Adapter, adapts interface of an existing class to another interface. For example eletrical adapter
When to use:
Using decorators you can wrap objects countless number of times since both target objects and decorators follow the same interface. The resulting object will get a stacking behavior of all wrappers.
Ending Part
Decorator great to use with Laravel or Symfony frameworks. His quite popular. Recommend to understand how to use
Reference on Resource
SUBSCRIBE TO CHANNEL:
Don't forget pls to click on 'Like', its giving additional motivation to work on channel.
Thank you for watching, for subscription and see you soon.
#mlaautomation #designpatterns #decorator #oopphp #php #tutorial #guide #phplessons #interview #questions #answers #devleoper #programmer #learncoding
This time on our consideration in this lesson - Decorator
Analogy
Let's say you have your own car service that provides various services. How do I invoice clients? Add consistently services and their cost - and in the end you will get the total amount to be paid. Here, each type of service is a "decorator".
In a nutshell
The "Decorator" pattern allows dynamic behavior of an object at runtime by wrapping it in an object of the "decorator" class.
Wikipedia
The Decorator pattern allows you to connect additional behavior (statically or dynamically) to an object without affecting the behavior of other objects of the same class. The pattern is often used to adhere to the principle of single responsibility (the principle of single responsibility), as it allows you to divide functionality between classes to solve specific problems.
Example
Link on the Code for Example(above):
What the difference composite vs decorator pattern?
The composite pattern allows you to build a hierarchical structure (such as a tree of elements) in a way that allows your external code to view the entire structure as a single entity. So the interface to a leaf entity is exactly the same as the entity for a compound entity. So the essence is that all elements in your composite structure have the same interface even though some are leaf nodes and others are entire structures. User interfaces often use this approach to allow easy composability.
The decorator pattern allows an entity to completely contain another entity so that using the decorator looks identical to the contained entity. This allows the decorator to modify the behaviour and/or content of whatever it is encapsulating without changing the outward appearance of the entity. For example, you might use a decorator to add logging output on the usage of the contained element without changing any behaviour of the contained element.
Decorator vs Adapter
Decorator, attach additional responsibilities to an object dynamically. For example adding sugar in a coffee.
Adapter, adapts interface of an existing class to another interface. For example eletrical adapter
When to use:
Using decorators you can wrap objects countless number of times since both target objects and decorators follow the same interface. The resulting object will get a stacking behavior of all wrappers.
Ending Part
Decorator great to use with Laravel or Symfony frameworks. His quite popular. Recommend to understand how to use
Reference on Resource
SUBSCRIBE TO CHANNEL:
Don't forget pls to click on 'Like', its giving additional motivation to work on channel.
Thank you for watching, for subscription and see you soon.
#mlaautomation #designpatterns #decorator #oopphp #php #tutorial #guide #phplessons #interview #questions #answers #devleoper #programmer #learncoding