oop

  • submit to reddit

Practical PHP Refactoring: Introduce Null Object

In the scenario of today, we see repeated checks for an object's equality to null, false or another scalar value without behavior. These checks take a form...

0 replies - 4288 views - 10/26/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Conditional with Polymorphism

In the scenario of today, an if chooses to execute different behavior depending on the type of an object. We should define "type" very looosely; for...

0 replies - 4134 views - 10/24/11 by Giorgio Sironi in Articles

Tell, Don't Ask in the case of a web service

This is a language agnostic post: it is valid for each object-oriented imperative language like Java, C#, PHP. Let's start from the beginning: a web service...

8 replies - 6800 views - 10/20/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Nested Conditionals with Guard Clauses

We agree that polymorphism eliminates many cases where if() statements are necessary. However, if we have a tangled conditional, it's better to simplify it as...

0 replies - 3099 views - 10/19/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Consolidate Duplicate Conditional Fragments

A piece of code is contained in all legs of a conditional: an obvious solution is to move it outside to simplify the branches. It may seem stupid to come up...

0 replies - 2563 views - 10/12/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Consolidate Conditional Expression

In this new article we continue to tackle conditional expressions, and their evolution towards polymorphism.In the scenario of today, multiple conditions lead...

0 replies - 2720 views - 10/10/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Decompose Conditional

The terminology we will use in these articles on conditionals will be the following:a conditional is a whole if/else or switch statement and its content. It is...

0 replies - 3649 views - 10/05/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Subclass with Fields

Sometimes a refactoring that start from type codes take the inverse direction.One common case is when a hierarchy of subclasses presents variations only in...

0 replies - 3552 views - 10/03/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Type Code with State or Strategy

This article is the third and last part of the refactoring from type codes miniseries.First, we saw a case where no behavior was modified by the type code...

0 replies - 4773 views - 09/28/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Type Code with Subclasses

This is the second part in the refactoring from type codes miniseries: type codes are scalar fields that can assume a finite number of values. The assumption...

0 replies - 4565 views - 09/26/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Type Code with Class

The scenario of today will be familiar to many developers which have experience with ENUM database fields: it consists in a numerical or fixed string type code...

0 replies - 4538 views - 09/21/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Record with Data Class

We often find ourselves tempted by the shortcut of using directly a record-like data structure provided by the language or a framework. There are many example...

1 replies - 4473 views - 09/19/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Encapsulate Collection

In the scenario of today, a method returns an array (or a collection object) kept as a field on the object, or allows it to be set with a brand new...

0 replies - 4487 views - 09/14/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Encapsulate Field

The public field has been abandoned in modern OOP for a return to the origins (although the getter/setter by default solution is not much better.) An object...

0 replies - 3947 views - 09/12/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Change Bidirectional Association to Unidirectional

This refactoring is the inverse of Change Unidirectional Association to Bidirectional. We start from a bidirectional association, where two objects reference...

0 replies - 4197 views - 09/05/11 by Giorgio Sironi in Articles