 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: Handling Collections of Aggregate Roots - the Repository Pattern
by Chris Cornutt May 17, 2012 @ 08:44:37
On PHPMaster.com today they have a new tutorial focusing on using the Repository (a part of the domain driven design architecture) to enhance your model's current functionality.
Unlike mappers, though, which are part of the infrastructure, a repository characterizes itself as speaking the model's language, as it's intimately bound to it. And because of its implicit dependency on the mappers, it preserves the persistence ignorance as well, therefore providing a higher level of data abstraction, much closer to the domain objects.
Included in the tutorial is the full code you'll need to create a simple UserInterface class and a User model that extends it. He also makes a UserCollection class to handle working with multiple User objects and a UserMapper to handle the actual data source fetching. Finally, he implements the Repository on top of this base structure showing how it lays on top of everything via the UserMapperInterface instance. At the end some example code showing it in use is also included - making the PDO connection, creating the UserRepository and fetching by a few different data types (email, name and role).
voice your opinion now!
repository pattern domaindriven architecture tutorial mapper
Ralph Schindler's Blog: PHP Constructor Best Practices And The Prototype Pattern
by Chris Cornutt March 12, 2012 @ 11:26:10
In this new post Ralph Schindler takes a look at the Prototype design pattern and uses it to illustrate some best practices in using constructors in PHP.
If your knowledge of constructors ends with "the place where I put my object initialization code," read on. While this is mostly what a constructor is, the way a developer crafts their class constructor greatly impacts the initial API of a particular class/object; which ultimately affects usability and extensibility. After all, the constructor is the first impression a particular class can make.
He starts at ground level, reintroducing what a constructor is and what it should (and shouldn't) be used for. He talks about constructor overloading, constructor injection, dynamic class extension and using the Prototype pattern to create "an unlimited number of objects of a particular type, with dependencies in tact, each with slight variations." He gives an example with a "DbAdapter" class, showing dynamic class instantiation and how to, using the Prototype method, inject a DbAdapter object and have your class use that instead.
voice your opinion now!
constructor best practice prototype design pattern
PHPMaster.com: Understanding the Observer Pattern
by Chris Cornutt February 23, 2012 @ 11:39:10
PHPMaster.com has a new tutorial looking at another popular design pattern, the Observer pattern, and sharing some example code putting it to use. (Their other design pattern articles include ones on command and factory patterns).
In this article I'll show you how to implement the Observer Pattern. You'll learn how various classes in the pattern relate to one another as subject and observers, how the subject notifies observers of a change in its state, and how to identify scenarios where it would be suitable to use the Observer Pattern in your own code.
The introduce the pattern by using an abstract "Observer" and "Subject" (that defines "attach", "detach", "getState", "setState", "notify" and "getObservers" methods) observer classes to coordinate the attached classes. They extend these classes with "Auth" and "Auth_ForumHook" show how to attach the "Auth_ForumHook" classes to the main "Auth" observer manager and change the state of the observer to notify it of an update.
You can find a more detailed explanation of the Observer pattern on Wikipedia.
voice your opinion now!
observer design pattern tutorial authorization
DZone.com: Practical Testing Patterns - Redux
by Chris Cornutt June 02, 2011 @ 12:12:25
A while back we posted about a series of articles Giorgio Sironi was doing about some of the more practical applications of testing patterns in PHP unit testing. He' been building on the series ever since and has lots of great patterns you can use to more correctly structure your testing practices.
The current list includes:
There's lots more where these came from, all divided into sections like "Fixture Setup", "Test Double" and "Database Isolation" patterns. You can find the full list so far here.
voice your opinion now!
testing pattern unittest practical
Label Media Blog: Design Patterns in PHP - Observer Pattern
by Chris Cornutt February 11, 2011 @ 11:03:21
Tom Rawcliffe has posted the latest in his design patterns series covering some of the most common patterns and how they would work in PHP. In this new post he looks at the observer pattern.
So far in my series of articles on design patterns in PHP we've looked at a creational pattern, a structural pattern and a behavioral pattern. Today I'll be taking a closer look at another behavioral pattern - the observer. The observer pattern (also known as the Subscribe/Publish Pattern) is used to notify one object, the observer, about a change of state from another object, the subject.
He gives the layout of the pattern in a simple UML diagram before moving into the description and code. His sample builds a Users object that has a set of observers on it. His custom observer is a logger that, when a change is made on the Users, it writes out a value of the current object.
voice your opinion now!
observer design pattern tutorial series
Wil Sinclair's Blog: Process Patterns
by Chris Cornutt December 30, 2010 @ 08:34:01
On the Zend Developer Zone today there's a new post mentioning something from Wil Sinclair about something he calls "process patterns" in software development.
From Wil's post:
I need a word for several engineers working on the same project that isn't 'team'. Why? Because most engineers working on the same project aren't working together as a team. This is why I believe in process patterns. Note: I didn't say that I believe in processes, because I don't. [...] You name a methodology, and I don't believe in it. But I do believe that there are some process patterns that can dramatically improve team productivity.
These patterns are things that are common to several of the processes common to software development - like backlogs, test driven development, etc - but don't have to be considered as something that only comes with XP or Scrum and shouldn't be used outside them. There's even a whole other site dedicated to defining these patterns and where the ideas came from. Oh, and don't forget to add Wil's new word to your vocabulary - "hackle", two or more engineers working together on one project (not necessarily as a team).
voice your opinion now!
process pattern development hackle software
Label Media Blog: Design Patterns in PHP - Strategy Pattern
by Chris Cornutt November 30, 2010 @ 12:48:26
On the Label Media blog today Tom Rawcliffe continues his series looking at design patterns (see here for his look at the Factory pattern) with this new post focusing in on the Strategy pattern.
The Strategy Pattern is used to decouple an algorithm from the context in which it is used. I'm going to equate this example to a real world scenario starring a man, I'll call him Bob.
In his example Bob heads to work and takes whatever way he wants to get there. His boss only cares that he makes it there, not the path he takes. Bob can take many different ways ("strategies") to get there, but how is up to him. Tom illustrates this with a bit of sample code with a "bob.php" that can use any number of other classes/methods to get to work (like commute, the train or a car).
voice your opinion now!
designpattern strategy pattern tutorial
Ibuildings techPortal: Optimising MHVC Web Applications for Performance
by Chris Cornutt November 17, 2010 @ 08:17:19
On the Ibuildings techPortal there's a new tutorial from Sam de Freyssinet that follows up on a previous article he wrote about using HMVC (Hierarchical-Model-View-Controller). In this new article, he talks about some of the things you can do with that pattern to increase performance.
Hierarchical-MVC has been shown to make large web applications easier to scale out, but there is a price to pay- namely overall performance. This article will investigate ways of improving performance within HMVC web applications using asynchronous processing and some good old caching techniques. Predominantly this article will use examples written for the Kohana Framework; however all the concepts portrayed here could apply to any framework or web application.
He starts by pointing out what's wrong with the typical HMVC application - namely that the clean separation of code structure (the hierarchical part) costs the application in overall speed and memory usage. He suggests a simple technology for helping ease the load - caching as much information as possible, mostly in the HTTP client code since HMVC applications rely heavily on it. Code samples includd show how to implement this in a simple Kohana application.
voice your opinion now!
hmvc hierarchical pattern cache performance overhead
|
Community Events
Don't see your event here? Let us know!
|