[squeak-dev] The Trunk: Environments-cmm.37.mcz
Chris Muller
ma.chris.m at gmail.com
Sat Dec 21 18:01:57 UTC 2013
> 1) each class that declares instance variables has exactly one
> initialization method
Well then you can't have more than one constructor type then. Not all
objects can follow a path down to a single constructor on the
class-side that ends up calling #initializeWtih:... In several cases,
you'll need #initializeWithThis: and #initializeWithThat:. And, in
both cases, you want to call #initialize from the top of them. That's
repeating yourself and unconventional.
> 2) each initialization method must leave the instance in a valid state
Of course, as does any initialization method like CPM methods.
> 3) each initialization method is named verbosely starting with
> 'initializeWith' and describes its parameters
The ONLY reason you call it "initializeWithThis:that:other:thing:"
instead of "setThis:that:other:thing:" is because you want to repeat
yourself by calling #initalize at the top of each method.
Also, your #1 said "exactly-one initialization method," but here you
say, "each initialization method."
> 4) each initialization method must call the initialization method of its
> super class
So who calls "super initialize" then?
> 5) the super initializer probably has a different name (see #2), so we send
> it to self, not super, to allow overrides
Of course, that's true for everything, it has nothing to do with this
(anti)pattern.
> 6) there is one or more class-side constructors which send #basicNew and the
> initialization message
Why basicNew instead of new? Honestly, there's no good reason for
that and it forces you to repeat yourself in all of your
#initializeWith: methods.
> I've found that this is a subtle, but profoundly useful pattern. It
I'd call it an anti-pattern.
> eliminates the need for trivial setters just to get a valid instance
> created, which allows for better encapsulation of state and often full
> immutability. I've been using it long enough that I've started to see
> setters as a code smell.
You and Frank both need to read the CPM pattern because you missed it.
You're confusing CPM as a setter.
More information about the Squeak-dev
mailing list
|