Posts For Tag: OOP
Does Static Factory Violate Open/Closed Principle?
25 Jan 2018
Consider an application that provides some statistics reports. Reports are present in different formats: JSON for API, HTML for viewing in a browser and pdf for printing on the paper. It has StatisticsController that receives a required format from the...
READ MORESingleton: Anti-Pattern Or Not
11 Jul 2017
Definition — “Do you know any Singleton jokes?” — “Just one.” Singleton is one of the simplest patterns to understand. The main goal of it is to limit the existence of only one instance of the class. The reason for...
READ MOREWhen to use Factory instead of direct object construction
22 May 2017
Factory is an object responsible for creating other objects. It is often considered a good practice to move the process of object creation from the consumer’s code into the factory. Even more, some people say that you should avoid the...
READ MOREAntipattern Poltergeist
11 May 2017
The opposite of the God class is Poltergeist. It are some sort of useless class. The main characteristic of a poltergeist: it represents a piece of control logic for making things happen and then it disappears, no state, no data...
READ MOREDependency Injection Smells
04 May 2017
In the previous article, I have discussed the difference between constructor and setter injections. Now, it’s time to pay attention to some examples of how not to use Dependency Injection. Too many dependencies When a class has a lot of...
READ MOREDependency Injection: Constructor vs Setter
25 Apr 2017
In an object-oriented application, objects constantly interact with each other, either by calling methods and receiving information from another object, or changing the state of this object. In any case, objects often depend on each other. Consider this simple. Delivery...
READ MOREOOP Desing Principle: Dont Repeat Yourself
19 Apr 2017
The DRY principle is stated as Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. It is always easy to copy and paste some code when you need it in some other place of your...
READ MOREKISS Your Application
13 Apr 2017
Another principle of object-oriented design is called KISS, that stands for Keep it short and simple. But there also some interpretations such as keep it simple, stupid!, keep it simple and stupid or keep it simple and straightforward. Sounds too...
READ MOREMaking Polymorph
09 Apr 2017
In object-oriented programming, polymorphism is one of the most important concepts. The general description of the word polymorphism in the programming community is the provision of a single interface to entities of different types. There are several types of polymorphism,...
READ MOREPHP: How to override trait method and call it from the overridden one?
01 Apr 2017
Consider this example, when we have a trait and a class that uses this trait. But we want to override a trait’s method and also we want to call the initial trait’s method. How can we do it? We can’t...
READ MOREOpen/Closed Principle
27 Mar 2017
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. Let’s decrypt this description a bit. Open means that it should be simple to change the behaviour of a particular entity. Closed means chaging behavior...
READ MORETraits: Copy-Paste Behavior
20 Mar 2017
In PHP we don’t have multiple inheritance. Our child classes should always have only one parent class. Some people argue that this is a bad approach because they want to inherit from multiple classes to get access to some useful...
READ MOREInheritance: Families Of Related Types
18 Mar 2017
What’s the first thing that comes to your mind when you hear word inheritance? I have no doubt that it is code reuse. Right? Let’s forget about code reuse and start from scratch. In one of my previous posts, I...
READ MOREOOP Design Antipattern: God Object
11 Mar 2017
God Object means an object that does too much or knows too much. To be more detailed this situation occurs when an object has knowledge of many different large parts of the system, it has an influence on them, the...
READ MOREReplace Conditionals With Composition And Polymorphism
25 Feb 2017
Conditionals are an integral part of any programming language. We use them every day, so why in OOP they are considered as a code smell? Conditioт becomes a code smell when we have to check an object’s type in order...
READ MOREAbstract Class VS Interface
05 Feb 2017
Abstract class Abstract class represents a new data type in your application. Classes define a blueprint for the objects, and we know how to use these objects of the certain class type. Just like we know how to use strings...
READ MOREThe Decision Between Inheritance And Composition
08 Jan 2017
There are two fundamental ways to establish relationships between class in object-oriented design: inheritance and composition. First of all, let’s determine that there is no better or worse principle in object-oriented design. But there is an appropriate design for the...
READ MOREOOP Design Principle: The Principle of Least Knowledge
11 Dec 2016
In this article, I’m going to touch a problem known by many names, one of which is the Law of Demeter. But honestly speaking, it is not even a law, but a guideline. The rules promoted by this principle are:...
READ MOREWell written methods rule: one level of indentation
17 Jun 2016
What is the main purpose of creating a new method? To reduce the complexity of the code. We create a method to hide and forget some logic. Later we use methods and ignore their logic details. One of the signs...
READ MOREThree Rules to Respect Liskov Substitution Principle
02 May 2016
Program to an Interface, not implementation Let’s refresh a classic definition: objects in a program should be replaceable with instances of their subtypes without altering the correctness of the program. In the world of PHP it often means programming to...
READ MOREPHP: Interface and Abstract Class
19 Apr 2016
One of the most popular questions on the interview is “What is the difference in interfaces and abstract classes?”. So let’s see the difference. Interfaces Before getting into theory, let’s refresh in memory how an interface is defined: <?php interface...
READ MORESymfony Event Dispatcher
15 Apr 2016
The idea of event dispatcher is to allow communication between different parts of the application without coupling them. In this way, an application can be easily maintained and extended, and it does not have to know about the classes that...
READ MOREAbstraction in PHP: Define Type Not Class
20 Mar 2016
A trap of code reuse What is an abstraction in PHP? Everybody understands it, but it is sometimes difficult to explain. The first thing that comes to mind is “it is about code reuse”. And it is what we have...
READ MORERECENT POSTS
- Myths About Asynchronous PHP: It Is Not Truly Asynchronous
- DriftPHP: Quick Start
- ReactPHP Internals: Event Loop Timers
- Interview with Marc Morera: About DriftPHP
- Introducing PHP-Watcher
- Live Reloading PHP Applications With Nodemon
- Building a RESTful API Using ReactPHP: JWT Authentication
- Building a RESTful API Using ReactPHP: Basic Authentication
- Building a RESTful API Using ReactPHP and MySQL
- How To Speed Up The Code Review
- Managing Concurrency: From Promises to Coroutines
- Fast Web Scraping With ReactPHP: Download All Images From a Website
- PHP Roundtable 76: Concurrency, Generators & Coroutines - Oh My!
- Fast Web Scraping With ReactPHP. Part 3: Using Proxy
- Sending Email Asynchronously With ReactPHP Child Processes
- Fast Web Scraping With ReactPHP. Part 2: Throttling Requests
- Using Router With ReactPHP Http Component
- Working With FileSystem In ReactPHP
- Amp Promises: From Generators To Coroutines
- Fast Web Scraping With ReactPHP