Showing posts with label pattern. Show all posts
Showing posts with label pattern. Show all posts

Friday, November 21, 2008

Some thoughts about reading Patterns of Enterprise Application Architecture

First of all, it is a good book. There is no doubt for that. Its author name, Martin Fowler, is a guarantee in quality.

However, I think it might be better if we read it from its Part 2: The Patterns. And then refer back to Part 1: The Narratives. The reason is simple, if you don't have any knowledge of those patterns, reading part 1 doesn't help you a lot and would not offer you any valuable information. If we start from Part 2 and get a solid knowledge of the patterns and their implementation, we can easily link them with our practice. And it may be just like, ah ha, that is it! And then if we turn back to part 1, we can get our knowledge solid.

It is just my personal thought about reading this book.

Sunday, November 16, 2008

Refactor Conditional Logic

In the book Refactoring to Patterns:
"Martin Fowler writes, "One of the most common areas of complexity in a program lies in complex conditional logic". We often find such logic in algorithms because they tend to grow, becoming more sophisticated over time. "

Conditional logic contain two kinds of statement: if...else... and switch...case...

The book Refactoring presents us below refactoring techniques:

Replace Type Code with Class
Replace Type Code with Subclasses
Replace Type Code with State/Strategy

Decompose Conditional
Consolidate Conditional Expression
Consolidate Duplicate Conditional Fragments
Remove Control Flag
Replace Nested Conditional with Guard Clauses
Replace Conditional with Polymorphism
Introduce Null Object
Introduce Assertion

The book Refactoring to Patterns also demonstrate below conditional logic related refactorings:

Replace Conditional Logic with Strategy
Replace Conditional Dispatcher with Command
Move Accumulation to Visitor
Move Embellishment to Decorator
Replace State-Altering Conditionals with State
Introduce Null Object

As conditional logic is a common issue that increase a program's complexity and reduce its readability, examine these refactoring techniques become instructive.