Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Extending Template Classes - Best Practices

Reply
Thread Tools

Extending Template Classes - Best Practices

 
 
Tom
Guest
Posts: n/a
 
      11-02-2011
Hi,

I am trying to understand best practices in extending template container
classes. Say one has implemented an effecient parameterised tree
container that does not allow for duplicate values. Let us further
assume the tree method is parameterised by a single type T and a
functional C . The functional defines an order relation on the tree and
is provided a default value say std::less< T >. The tree interface
supports a minimal interface, providing insert, and remove methods. One
would now like to implement a parameterised Set container. Let us
suppose there are two cases here

- The set supports the same interface - insert/remove but with slightly
different implementation from the tree

- The set supports and augmented interface - insert/remove (with no
change in implementation), and additional methods such as union
intersection and complement.

In either case what is the appropriate approach, i.e set composes tree
or set inherits tree or tree is also parameterised by another type
(traits ?) that makes it behave as a set alternatively ?

What would be a good resource (book/website) to learn more about such
issues in developing parameterised classes and complexities of name
lookup rules for parameterised class hierarchies.

regards
Tom

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-02-2011
On 02.11.2011 01:08, Tom wrote:
> Hi,
>
> I am trying to understand best practices in extending template container
> classes. Say one has implemented an effecient parameterised tree
> container that does not allow for duplicate values. Let us further
> assume the tree method is parameterised by a single type T and a
> functional C . The functional defines an order relation on the tree and
> is provided a default value say std::less< T>. The tree interface
> supports a minimal interface, providing insert, and remove methods. One
> would now like to implement a parameterised Set container. Let us
> suppose there are two cases here
>
> - The set supports the same interface - insert/remove but with slightly
> different implementation from the tree
>
> - The set supports and augmented interface - insert/remove (with no
> change in implementation), and additional methods such as union
> intersection and complement.
>
> In either case what is the appropriate approach, i.e set composes tree
> or set inherits tree or tree is also parameterised by another type
> (traits ?) that makes it behave as a set alternatively ?
>
> What would be a good resource (book/website) to learn more about such
> issues in developing parameterised classes and complexities of name
> lookup rules for parameterised class hierarchies.


At the design level a set is different from a tree.

So the tree stuff should not be publicly available from the set interface.

In practice containment is generally preferable over private or
protected inheritance, but whatever works & feels right (e.g.
convenience) and isn't immediately attacked by code reviewer.


Cheers & hth.,
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-02-2011
On Wed, 2011-11-02, Tom wrote:
> Hi,
>
> I am trying to understand best practices in extending template container
> classes. Say one has implemented an effecient parameterised tree
> container that does not allow for duplicate values. Let us further
> assume the tree method is parameterised by a single type T and a
> functional C .

....

> What would be a good resource (book/website) to learn more about such
> issues in developing parameterised classes and complexities of name
> lookup rules for parameterised class hierarchies.


I don't see how your problem relates to templates -- are you sure
you're not confusing yourself? Step back and think of the two plain
classes SetOfFoo and TreeOfFoo (for some example type Foo) if you
notice your head beginning to spin. (That's what I do.)

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Identitity Template Problem - Best Practices - What order to makechanges johkar XML 2 10-19-2009 02:40 AM
Best practices for web template jacob@graftechnology.com HTML 2 11-27-2007 02:40 PM
Best Practices for System.Net Classes what? Janus Knudsen ASP .Net 4 06-26-2004 06:46 PM
best practices - how to organize classes Miranda Evans Python 1 11-25-2003 04:36 PM
Best Practices - solution - namespaces - classes Craig Deelsnyder ASP .Net 1 08-04-2003 11:27 AM



Advertisments