New answers tagged

2

My go-to for programming patterns these days are games, because it is easy to create compelling examples. It has never occurred to me before to have a factory return its own subclass, so I apologise if I turn out to be off the mark here! However, the use I immediately thought of was an enemy factory that only provides instances of its subclasses, randomly (...


2

I don't have a good answer to this. However here are my thoughts. Named constructors A good use for static factory, is to implement named constructors: Java, C#, C++, et al do not have named constructors. However named constructors can be useful, as they allow you to document different ways of constructing an object. Therefore use a static factory, to create ...


2

I would first ask what that hierarchy buys you overall in an application and, more important, in the student understanding. In general, I find concrete subclassing to be problematic and easily abused, as well as confusing. If you are satisfied that it is essential in some way, then an example could involve the characteristics of some figures coming from a ...


Top 50 recent answers are included