Embrace Factories
From BriansWiki
Contents |
[edit] Presenter
[edit] Rob Gonda
[edit] OOP Problems
- Object Creation and initializations
- Relationships wiring
- Manageability/moving keeping paths
- Cohesion Loose coupling
- Unit Testing
Create Objects in application scope and only application scope - other components can refer to this.
[edit] Design Patterns
Repeatable solution to commonly occurring problems
[edit] Object Factory
Collects information in a centralized repository for paths and dependencies All objects depend on the factory
User = Application.factory.getInstance(‘user’); This creates a pointer a singleton instance of the user object
The factory passes an instance of itself to the object that it is creating, so there it can refer to all the factory variables.
The Factory created the object if necessary, or reuses an existing instance if it exists. In the init function the object is handed (this) which refers back to the factory, This ensures that there is a single repository for all the objects
The Factory is scoped in the application
All consumers get components from the factory
Inversion of control and Dependency definition, which is an architectural model that adds all the components that an application needs (the application is handed the objects rather than creating them itself.
[edit] Dependency Injection
Three type of dependency injection
[edit] Constructor -
On init all the objects are passed to it
[edit] Setter -
There is a problem if there are interdependencies between components they will try to create each other till all resources are consumed. To avoid this, once the component is created it receives all its objects after creation, If you had to pick one, Setters are more dependable
[edit] Dependency Injection III
This is great for unit testing, since the components are loosely coupled. And we can use Mock collaborators during testing.
[edit] ColdSpring
An object factory on steroids Common to most important frameworks, inspired by the spring framework, it is IOD for CFC’s and allows setters and constructor style injection,
[edit] Polymorphism
Doesn’t care about collaborators implementation – leads to swapability Where collaborators are replaced with a stub of the real component (like if AD goes down, you can use am XML lookup instead) Perfect for unit testing (again)
[edit] ColdSpring: Tiers and Layers
Any Client sees the same service layer which then goes to the backend database and other business components
Façade: creating an interface that can translate a request for an object or method to the current implementation.
[edit] ColdSpring Config file
Beans: ID Class Name Specify singleton true or false Pass references to dependent components, or the properties if you are using the setter method Installing ColdSpring hhtp://ColdspringFramework.org ColdSpring does lazy loading of components, they are only created the first time you request them.
[edit] ColdSpring Auto-Wiring
You can just tell ColdSpring to auto-wire either by name or by type, this tells ColdSpring to look at the components constructors and look at the setter functions. The problem with this is that dependencies are undocumented. But for simple apps, it is a time saver. Another drawback is there is a performance hit to this process.
[edit] Aspect Orientated Programming
[edit] Front Controller integration
Mach II Model Glue Coldbox
[edit] Flash remoting Code Generation and mapping
ColdSpring can handle many environments that have different html, data nd other services, instead of creating a ColdSpring CML for each one, you pass an object that contains all the requirements for each one. The properties object will change depending in environment,
Then the Application CFC can use the CGI properties to determine the server name and then use the appropriate configuration for that server.
Note: Latest version of Galleon By Ray Camden is using a simple factory which is self contained.
