Andrew Lentvorski wrote:
[EMAIL PROTECTED] wrote:
On Fri, Mar 21, 2008 at 11:04:52AM -0700, Tom Gal wrote:
Lots, but then it's probably because I get to work on more vertically
integrated code. I use classes, and factories, and many common OO
design techniques, and think it's very helpful. I feel really bad when
I change my software or API, or a constant, and the LabView guys have
to go change a bunch of diagrams over and over.

By the time you get to the realm of factories and hardcore OO design patterns
your talking about a massive mature code base you are refactoring.

Or you are talking someone who has been bitten by this quite a lot and knows to *start* with these things.

For example, you almost *always* want a factory for your public interface. If you make your constructor part of your public API, it becomes very difficult when you need something slightly different.
This is very much a language specific thing. In languages like Java or C++, a constructor has a lot of restrictions associated with it that significantly limit their flexibility. In languages like Smalltalk, constructors aren't externally different from other class method, and so you don't really need the encapsulation of the factory pattern unless you have other factors to address.

Of course in C++, you have the option of just having a plain old function as your public entry point to creating an object, which can generally provide enough flexibility to address later changes.
Factories are often the difference between simply adding a parameter to your factory API (perhaps on another function) and having to inherit a whole new class because you can't overload the constructor a particular way.
I'm not sure I'd buy this one at all. In the "complex" scenario you described, you *could* always just add a parameter to the constructor API and the move behavior for each of Rect vs. Polar in to an object contained by Complex (i.e. use composition). Depending on your language, this would be a cheap and as flexible (from the caller's point of view) as anything else you might do.

--Chris

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to