Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

StarTutorial.com:
Understanding Design Patterns - Composite
Jun 29, 2018 @ 18:38:10

The StarTutorial site is back with the latest installment of their series covering common design patterns and their use in PHP. In this latest tutorial they cover the Composite pattern.

[The Composite pattern] allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

In their example, they tell a story about a Walmart worker that received comments from her manager about an issue with the number of cars per box. They define classes for each (Agnes, a Box and a Product), including basic functionality in each. They talk about possible ways to solve the "number of cars" problem in the code including conditional statements and other logic. This is pushed aside when a more sustainable solution is desired, one that makes use of common interfaces for multiple product types. The code examples for this new "composed" structure is included.

tagged: designpattern tutorial series composite

Link: https://www.startutorial.com/articles/view/understanding-design-patterns-composite

Marc Aube:
Design Pattern: Specification
May 25, 2015 @ 17:19:47

Marc Aube has a new post to his site that introduces you to the specification design pattern, a technique that's useful for ensuing the current state of an object is valid.

The specification pattern is a software design pattern used to codify business rules that state something about an object. These simple predicates determine if an object's state satisfies a certain business criteria. They can then be combined to form composite specifications using logical operators. Use a specification to encapsulate a business rule which does not belong inside entities or value objects, but is applied to them.

He suggests a few things the pattern could be useful for like validating the current state or define how an object should be created. He gives a few more "real world" examples and then gets into the code to create a custom specification. In his "CustomerIsPremium" spec he defines a single method on an interface to determine if the Customer given is correct. He then creates a class instance and encapsulates the logic inside its "isSatisfiedBy" method. He also includes a bit more complex example, showing how to create a composite specification for handling grouping like "and", "or" and "not" assertions. Finally he looks at how to build specifications that can be passed in and used as selection criteria. He does point out that this can leak database handling into the specification layer, however, and should really be avoided without a inversion of control method in place.

tagged: specification designpattern pattern example composite select validate

Link: http://marcaube.ca/2015/05/specifications/

PHPMaster.com:
Patterns for Flexible View Handling, Part 1 - Working with Composites
Aug 30, 2012 @ 13:32:36

PHPMaster.com has started up a new series today with the first part of a set of tutorials looking at design patterns that can be used in the handling of your views to make them more effective and easier to maintain.

To overcome your skepticism [of an easy to use, flexible view system], in this two-part tutorial I’ll show you how to implement from scratch a couple of customizable view handling modules by sinking our teeth into the goodies of the Composite and Decorator patterns.

He starts off by creating a foundation to work from - a basic View class that takes in data, allows for the setting of a template and combines it all together when "render()" is called. He then takes this example and applies the Composite pattern and creates interfaces for the template, container and view, implements them and shows how to attach views to other views. Each of these views is then rendered when the main "render()" method is called and the output is appended.

tagged: view handling mvc composite designpattern tutorial

Link:

Ralph Schindler's Blog:
Composite Rowsets For Many-To-Many Relationships Via Zend_Db_Table
Nov 16, 2010 @ 17:08:24

Ralph Schindler has posted a handy tutorial (along with some helpful code) to his blog today about handling many-to-many composite rowset relationships with the Zend_Db component of the Zend Framework.

One of the hardest problems to solve when developing an ORM of any complexity is in deciding how to handle the retrieval of rows that satisfy a many-to-many relationship, also known as a M:N relationship. [...] To model M:N relationships, database developers must get creative. By employing the use of a "3rd party", and by utilizing foreign keys that model a 1:N relationship, database developers can model a M:N relationship.

He looks at the Zend_Db_Table_Row class of the framework and how it works with these junction tables and how it has an issue where it returns the junction table columns too. A fix was released (in 1.10.2) for the framework to work correctly. Unfortunately, this also left those using the method out in the cold. So, Ralph has created his own workaround called a composite rowset. He includes an example snippet to give you an idea of how it works, but you can download the code from his github repository for a closer look.

tagged: composite rowset zendframework zenddbtable manytomany database

Link:

Rob Zienert's Blog:
Zend_Form Decorators and Composite Elements
Jun 23, 2010 @ 17:50:12

Rob Zienert has a new post to his blog today looking at Zend_Form decorators and composite elements to make for more powerful forms in your Zend Framework application.

Today had quite a number of Zend_Form-related questions in #zftalk. Everything from Decorators to Composite Elements, you know - the usual Zend_Form questions. What better way to answering questions than with a blog post and some sample code?

His illustration of decorators shows how to put each of the form elements inside of a "DI" tag to help makes the lives of the frontend developers that much simpler. For the composite elements he shows how to use them to group a set of selects into one object that is then validated through Zend_Date for valid date information. You can grab the code for each of these illustrations from this account on Github

tagged: zendform decorators composite tutorial

Link:

ZendCasts.com:
Writing Composite Zend_Form Elements
Mar 15, 2010 @ 16:33:48

A recent tutorial (screencast) has been posted to the ZendCasts.com site looking at creating custom Zend_Form elements when you need something more than just the usual, simple elements.

This video should help you build your own composite Zend_Form element. We’ll be building a phone element. The phone element will have 3 textboxes, one for geographic location, area code and local code. In the following videos will add a custom cell phone validator and some ajax validation.

You can grab a copy of the source if you'd like to follow along or you can just look around the repository to find the source for this and other great lessons from the site.

tagged: composite zendform element screencast tutorial zendframework

Link:

Matthew Weier O'Phinney's Blog:
Creating composite elements
Apr 14, 2009 @ 15:25:53

Based on an example in a previous blog post (seen here) Matthew Weier O'Phinney wanted to clear a few things up on the "date of birth" element he had mocked up in his Zend_Form example.

In my last post on decorators, I had an example that showed rendering a "date of birth" element [...]. This has prompted some questions about how this element might be represented as a Zend_Form_Element, as well as how a decorator might be written to encapsulate this logic. Fortunately, I'd already planned to tackle those very subjects for this post!

To be able to use the element in its current state the key lies in the setValue method. More correctly in the overriding of the setValue method. He includes an example class that is smart enough to use that custom form element. It has get and set methods for each of the date fields (month/day/year) and the set/getValue methods that can interact using them. He wraps this all up inside a form decorator and creates an instance of the Date element to help create and handle the properties it has.

tagged: create composite element date zendform decorator custom

Link:

Eran Galperin's Blog:
The Advancing PHP Developer Part 5: Design Patterns
Jul 14, 2008 @ 14:32:26

As a part of his "Advancing PHP Developer" series, Eran Galperin has posted part five, a look at design patterns and what they can do for you and your application.

A design pattern is a general reusable solution to a recurring design problem in object-oriented systems. Design patterns are essentially blueprints that suggest how to solve a particular set of OO design problems while adhering to OO best good-practices (which I've recounted in my Object Oriented part of this series).

He talks about one of the most popular examples - the Model/View/Controller design pattern that is used in many rapid development frameworks for PHP (including CodeIgniter and the Zend Framework). He also briefly mentions a few others like the composite, singleton and decorator patterns.

Other parts of this series include looks at testing, refactoring and coding standards.

tagged: designpattern mvc modelviewcontroller decorator composite singleton

Link:

Pádraic Brady's Blog:
Complex Views with the Zend Framework - Part 3: Composite View Pattern
Apr 27, 2007 @ 16:41:00

In his continuing look at using the composite design pattern inside the Zend Framework views (as helpers), Pádraic Brady has posted part three demonstrating the creation of complex views.

In this post, I offer a brief explanation of the Composite View pattern. It's beyond its scope to show an implementation using the Zend Framework though that's what I'm building up to accomplish in a later blog entry.

He goes through what the design pattern is (including a UML diagram showing it's relations) and how it's commonly used. Following this, he shows a little bit of the code in action that includes the use of an attach() method to include the "child Views" at certain locations.

tagged: designpattern composite view zendframework tutorial designpattern composite view zendframework tutorial

Link:

Pádraic Brady's Blog:
Complex Views with the Zend Framework - Part 3: Composite View Pattern
Apr 27, 2007 @ 16:41:00

In his continuing look at using the composite design pattern inside the Zend Framework views (as helpers), Pádraic Brady has posted part three demonstrating the creation of complex views.

In this post, I offer a brief explanation of the Composite View pattern. It's beyond its scope to show an implementation using the Zend Framework though that's what I'm building up to accomplish in a later blog entry.

He goes through what the design pattern is (including a UML diagram showing it's relations) and how it's commonly used. Following this, he shows a little bit of the code in action that includes the use of an attach() method to include the "child Views" at certain locations.

tagged: designpattern composite view zendframework tutorial designpattern composite view zendframework tutorial

Link:


Trending Topics: