Hello all,
I would like to know what is the practical difference between instance and class in the System Browser. Based on the Abstract Factory example from Alpert's 'Desgin Patterns' book:
1) Not using class:
Object subclass: #CarAssembler instanceVariableNames: 'factory'
factory: aCarFactory factory := aCarFactory.
And in the workspace:
assembler := CarAssembler new factory: RenaultFactory new.
car := assembler assembleCar.
Works fine.
2) Using class:
The book example actually uses:
Object subclass: #CarAssembler instanceVariableNames: 'factory'
CarAssembler class>> using aCarFactory
And then in the workspace:
assembler := CarAssembler using: RenaultFactory new.
car := assembler assembleCar.
That also works fine.
I see it as a semantic difference only. There must be more than that. The class approach would nevertheless have an instance variable of the name 'factory' in which the wished factory object will be found. That variable is here initialized to a RenaultFactory in both cases. What are the pros and cons of using or not using the class approach ?
Thanks,
Al