Design patterns with PHP
Does anyone have any good book recommendations on design patterns, and applying them in PHP? ...
Does anyone have any good book recommendations on design patterns, and applying them in PHP? ...
I've inherited a large Java app that uses Struts, Spring, and Hibernate. The classes and interfaces I deal with daily are: Struts Actions, Struts ActionForms, Value Objects, Service Interfaces and Implementations, DAO Interfaces and Implementations, and Entities. I'm pretty clear on the how and why of most of these, except I'm unsure abo...
I have a 'Purchase Order' class. It contains information about a single purchase order. I have a DAO class for database methods. Where should the responsibility reside for the methods that will load and update the purchase order? Should the PurchaseOrder class have '.update', 'insert', 'delete', and '.load' methods that use the DAO cla...
After having implemented the strategy pattern, I wanted to make an array of the interface-type, to which I can then add any concrete type. For those who don't know the strategy pattern: http://en.wikipedia.org/wiki/Strategy_pattern In this particular example I would want to make a StrategyInterface array, which I can then fill with con...
Is it possible to implement the Visitor Pattern respecting the Open/Closed Principle, but still be able to add new visitable classes? The Open/Closed Principle states that "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification". struct ConcreteVisitable1; struct ConcreteVisitabl...
I've looked at this explanation on Wikipedia, specifically the C++ sample, and fail to recognize the difference between just defining 3 classes, creating instances and calling them, and that example. What I saw was just placing two other classes into the process and cannot see where there would be a benefit. Now I'm sure I'm missing some...
There are numerous times you have an interface that accepts similar type arguments that have a separate domain logic meaning: public static class Database { public static bool HasAccess(string userId, string documentId) { return true; } } Now it's quite easy to have someone key documentId instead of userId and vice versa. One could...
I'm asking all of you who aren't using a library for this, but are constructing your own objects for managing data flowing to and from your database tables. Do I have a recordset object? one object per row of data? Both? Neither? Any suggestions or experiences welcome. Please don't tell me to use an ORM or other such toolkit. It's ov...
What is the standard way for allowing and implementing a plugin system for your application? In my last application I made a simple interface for all plugins that they must implement. I then load all assemblies in the apps directory and toss out any that don't implement that interface. One of the methods in the interface is a DoWork()...
I have a sort of tree structure that represent a hierarchy of layers in a map, divided by types of layers and categories. Each node can be a different class for different types of layers (but all nodes implement a common interface). I need to convert that class to an ASP.NET TreeView control. Each node in the input tree is a node in the...
I am primary a web developer but I do have a very good understanding of C++ and C#. However, recently I have writing a GUI application and I have started to get lost in how to handle the relationship between my controller and view logic. In PHP it was very easy - and I could write my own MVC pattern with my eyes closed - mainly because o...
I have seen arguments for using explicit interfaces as a method of locking a classes usage to that interface. The argument seems to be that by forcing others to program to the interface you can ensure better decoupling of the classes and allow easier testing. Example: public interface ICut { void Cut(); } public class Knife : ICut...
have you re-factored from an Active Record to a Data Mapper pattern? what conditions prompted the switch? i'm primarily interested in web based applications, but would like to know the challenges that accompany such a move in any environment. ...
This question is a follow-up from How to indicate that a method was unsuccessful. The xxx() Tryxxx() pattern is something that can be very useful in many libraries. I am wondering what is the best way to offer both implementations without duplicating my code. What is best: public int DoSomething(string a) { // might throw an excep...
I have been looking at the Model-View-ViewModel pattern that is suggested by several people out there (especially John Gossman, take a look at this post and this podcast), but what other patterns (if any) have people used and liked ... and where do they add value? I have also stumbled across: Model-View-ViewModel Presentation Model Da...
A program receives a list of Messages (base type). Each message in the list has to be processed according to it's type (descendant type). However, different messages need different inputs in order to be processed correctly. What is the following technique called? (I haven't checked this code in a compiler) abstract class MessageProc...
Imagine in the Global.asax.cs file I had an instance class as a private field, lets say like this: private MyClass _myClass = new MyClass(); and I had on Global a static method called GetMyClass() that gets the current HttpApplication and returns that instance. public static MyClass GetMyClass() { return ((Global)HttpContext.Curr...
Is it a good practice to implement event handling through WeakReference if that event is the only thing holding the reference and that we would need the object to be garbage collected? As an argument to this: Folks say that if you subscribe to something it’s your responsibility to unsubscribe and you should do it. ...
(function() { //codehere } )(); What is special about this kind of syntax? What does ()(); imply? ...
In my webapplication (C#, .Net 3.5), made up of a core class library (containing the business logic, data layer and a couple of utility classes), a windows service project, a webservice project and the website project, I have a couple of static classes in the core library used by all other projects. These classes (for example the Log cla...