refactoring

  • submit to reddit

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 - 3162 views - 10/19/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Remove Control Flag

Control flags are boolean variables used to determine if you should stop a cycle or go on for another iteration. Since iteration is one of the three basic...

0 replies - 3015 views - 10/17/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 - 2629 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 - 2783 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 - 3716 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 - 3617 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 - 4827 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 - 4635 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 - 4621 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 - 4555 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 - 4592 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 - 4025 views - 09/12/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Replace Magic Number with Symbolic Constant

In the scenario of today, we have a literal number, such as 42, scattered across the code base. Alternatively, this number may be just written in a single...

0 replies - 4707 views - 09/07/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 - 4268 views - 09/05/11 by Giorgio Sironi in Articles

Practical PHP Refactoring: Change Unidirectional Association to Bidirectional

Object graphs are built by maintaining references to other objects inside an object's fields (usually private). These associations are persisted and stored by...

0 replies - 4469 views - 08/31/11 by Giorgio Sironi in Articles