filmov
tv
Singleton - Design Pattern in PHP | OOP Design Patterns | What and How to use it?
Показать описание
0:03 - Hey Guys, do you want to learn programming, you are on the right way. On this channel we learning programming and how to code.
Today we going to learn Singleton pattern. Its one of easist pattern in Creational group.
what else do you want to learn from MLA Automation? Comment down below and let us know so we can create more such tutorials for you.
2:29 - Analogy
A country can only have one president. He must act when circumstances and duty call for it. In this case, the president is a loner.
2:50 - In a nutshell
The template allows you to make sure that the created object is the only one in its class.
3:00 - Wikipedia
The Singleton pattern allows you to restrict class creation to a single object. This is convenient when coordinating actions within the system requires that an object be unique in its class.
In fact, the Singleton pattern is considered an anti-pattern, so you shouldn't get too carried away with it. It is not necessarily bad and is sometimes useful. But use it with caution, because Singleton brings global state to the application, so a change in one place can affect all other use cases, and debugging that is not easy. Other drawbacks of the pattern are that it makes your code tightly coupled, and mocking the Singleton can be difficult.
3:54 - Example
Make the constructor private, disable extensions, and create a static variable to hold the instance:
Link on the Code Example:
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 #singleton #tutorial #designpatterns #guide #interview #questions #answers #devleoper #programmer #oopphp #php #webdevelopment #learnCoding #programming
Today we going to learn Singleton pattern. Its one of easist pattern in Creational group.
what else do you want to learn from MLA Automation? Comment down below and let us know so we can create more such tutorials for you.
2:29 - Analogy
A country can only have one president. He must act when circumstances and duty call for it. In this case, the president is a loner.
2:50 - In a nutshell
The template allows you to make sure that the created object is the only one in its class.
3:00 - Wikipedia
The Singleton pattern allows you to restrict class creation to a single object. This is convenient when coordinating actions within the system requires that an object be unique in its class.
In fact, the Singleton pattern is considered an anti-pattern, so you shouldn't get too carried away with it. It is not necessarily bad and is sometimes useful. But use it with caution, because Singleton brings global state to the application, so a change in one place can affect all other use cases, and debugging that is not easy. Other drawbacks of the pattern are that it makes your code tightly coupled, and mocking the Singleton can be difficult.
3:54 - Example
Make the constructor private, disable extensions, and create a static variable to hold the instance:
Link on the Code Example:
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 #singleton #tutorial #designpatterns #guide #interview #questions #answers #devleoper #programmer #oopphp #php #webdevelopment #learnCoding #programming