6 Aug 23:13
Factory Method Pattern via Inner Classes
From: moffdub <moffdub <at> yahoo.com>
Subject: Factory Method Pattern via Inner Classes
Newsgroups: gmane.comp.programming.domain-driven-design
Date: 2008-08-06 21:16:17 GMT
Subject: Factory Method Pattern via Inner Classes
Newsgroups: gmane.comp.programming.domain-driven-design
Date: 2008-08-06 21:16:17 GMT
When it comes to Factories in DDD, most of the time, I am in the
situation to apply the Factory Method Pattern and not some of the
generalization-heavy patterns like Abstract Factory or Builder.
If I have a well-designed and encapsulated domain object for which I
want to provide a factory, usually there will be parts of the
construction that are simple, like directly initializing integers and
strings, and then other parts that are complicated -- the parts that
motivated me to create a factory in the first place.
Suppose I am in Java, so there are no "friend" modifiers or partial
classes. Since my domain object is well-encapsulated, I don't have
setters for each and every simple string or integer. They are
initialized through the constructor and changed only through other
non-setter methods that have domain meaning and encapsulate logic. If
I try to move this stuff from the constructor to a factory class, it
breaks because those simple strings and integers are private and not
accessible. The privatization of the domain object's constructor poses
a similar problem.
What are your thoughts on making the factory class a static member
class in order to have access to the privates:
public class Order
{
...
...
...
/* **** factory class **** */
(Continue reading)
RSS Feed