Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-11-28 18:32:14

Maarten Kronenburg wrote:
> "As an unsigned, modular or allocated integer is an integer, these are
> designed as (possibly template) classes derived from class integer with
> virtual member functions and operators, providing runtime polymorphism. Thus
> a pointer of type integer * may point to an unsigned, a modular or an
> allocated integer, which all behave like an integer (virtual methods) but
> with slightly different implementations.

Pointer polymorphism is not important to have. If it really was, there would be a polymorphic base for a sequences and strings in the standard library.

> This may be compared with a driver,
> which is an abstract class interface with only virtual functions.

The unsigned integer inherits from the signed one. While this does model arithmetics correctly (a natural number is an integer, after all), it is the unsigned integer that has richer functionality. It's clumsy and not extensible to use inheritance in such a case.

Allocation is orthogonal to all other properties, it applies to signed, unsigned, and modular integers - so this part is even worse.

> The
> integer and a driver have in common that they are both very close to the
> hardware.

You said so already - and it doesn't make that lame excuse any better to repeat it :-).

> This is also the reason that for this basic type only basic
> language elements are used, and not design patterns like singletons, object
> factories and smart pointers, which should be used at a higher abstraction
> level."

Why do you think so? What are "basic language elements"? What is an "object factory" (never heard of it)? Is there a design pattern called "smart pointer" (yeah, there are smart pointers but these are not design patterns, AFAIK)?

Really interesting that having a fancy name for "struct with static function" makes it non-basic ;-)...

> In an earlier discussion I have mentioned that there is a scale between
> compile-time (static) polymorphism on the left to run-time (dynamic)
> polymorphism on the right. Then the following items can be ordered from left
> to right:
> containers strings integers drivers.

No. Drivers are drivers. And strings and arbitrary precision integers are containers with special operations.
It might feel like writing a driver to you - but these are details specific to your implementation that really should not have any impact on the interface you choose!

Let's continue this discussion once you are really interested in improving the design.



Boost list run by bdawes at, gregod at, cpdaniel at, john at