[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Coding styles and patterns (Re: Miscellanous stuff)
Peter Burns wrote:
> I wont try to explain what patterns are all about since I'lll probably only
> confuse you.
Quoting from the book:
Christopher Alexander says, ''Each pattern describes a problem which
Occurs over and over again in our environment, and then describes the
core
of the solution to that problem, in such a way that you can use this
solution a
million times over, without ever doing it the same way twice.''
[AIS+77,page
x]
Design patterns are simply an attempt to formalize a common design problem
and the core of the typical correct solution for that problem.
> I implemented the AbstractFactory pattern for
> PenguinSound. It in ppsFactory.hpp. I;'m sure it can be improved. I've used
> it to generate concrete instances of ppsAudio and ppsSample.
You don't implement patterns, you apply them. The map between patternsand
classes is rarely one to one. In the example above I can see the Factory
Method pattern being useful as part of the design of the main sound object
(I'll
assume it's called ppsDevice). This object would have several methods which
would take various parameters and return references to ppsAudio or ppsSample
objects. The distinction here is that the new objects are requested from the
ppsDevice object rather than created from scratch using the new operator. This
is the essence of the Factory Method pattern. The Abstract Factory pattern
goes
one step further and defines the interface for creating these classes in an
abstract
fashion so that multiple subclasses can inherit this interface and instantiate
the
appropriate class for the given factory. I'm not sure how this is useful,
unless you
plan to use the Abstract Factory pattern to build cross platform support.
Since
game makers will undoubtedly have to recompile for each platform, it seems
inefficient to build this layer of abstraction in.
Using a consistent naming convention for the application of the pattern is
important. MS DicrectX makes heavy use of the Factory Method pattern, using
the 'Create' prefix for all the factory methods.
The design patterns book assumes that you are willing to make use of multiple
inheritance. I would think one would want to avoid multiple inheritance.
Rex.