Re: class hirachy problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Kristian,

[Note:  off topic for the GCC forum.]

In designing a factory class, you are faced with several options.

Your factory can be intimately familiar with the things it produces.

OR... your factory can be ignorant of the things it produces, and the things
it produces register themselves with the factory (presumably with their own
smaller factory functions) as part of an initialization routine.

OR... some combination of the above.

Typically, for factories that produce an assortment of objects I prefer
ignorant factories.  But they tend to be more work to design and code.
However, they're also more robust and extensible, and better encapsulation
since the objects produced by the factory are responsible for their own role
in their fabrication (their own factory routine plumbed into the ignorant
factory).

On the other hand, ignorant factories can be overkill.

All depends on the problem.

Since I'm not exactly sure how your objects create themselves, it's hard for
me to say how you should do it.

However, as a general rule of thumb, whenever I see a lot of dynamic_cast
and testing for NULL or switch/case based on typing (RTTI or homegrown),
that screams out to me that there's probably a candidate for the interface
pattern.  And CAlpha would be the prime candidate class to represent that
interface pattern.

I only very rarely use dynamic_casts in my applications.  Pretend they have
an extremely high overhead, like a sleep(5) in there.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux