Design Problem 2

J

jp

Hi.
I have another design problem. I hope someone can help me. Thanks in
advance.

I want to write a "library" consisting in a bunch of objects like
Info, Utils, etc..

I made a member with each of these inside de main class (the
"library") and made the constructors private for Info, Utils, etc. and
made them friend classes of the main class.

Is this the right approach or should I use heritance from a base
class? I also need to access some of the methods in Utils from Info,
for instance, Format date function, trims, etc. etc. meaning that
utils will be accessible from outside the library and from within.

LIBRARY
|_ INFO
|_ UTILS
|_ etc.
 
V

Victor Bazarov

I have another design problem. I hope someone can help me. Thanks in
advance.

I want to write a "library" consisting in a bunch of objects like
Info, Utils, etc..

I made a member with each of these inside de main class (the
"library") and made the constructors private for Info, Utils, etc. and
made them friend classes of the main class.

Is this the right approach or should I use heritance from a base
class? I also need to access some of the methods in Utils from Info,
for instance, Format date function, trims, etc. etc. meaning that
utils will be accessible from outside the library and from within.

LIBRARY
|_ INFO
|_ UTILS
|_ etc.

This is not really a language issue, is it? Please consider asking in
'comp.object'.

Generally speaking, you need to start with the *use* of the
class/object, not with how you want to implement it. Implementation is
subordinate to the purpose. What is the purpose of 'Info'? What is the
purpose of 'Util'? To answer those questions you need to look at how
they are used, by whom, what information flows from the user to the
tool. Now, whether they need to inherit from a common class, you need
to decide whether they have anything in common. If they do, extract the
common part (of functionality or data) and put it in the base class
(that's how many beginner OOD courses were taught in my time, some years
ago, and the times do change, so check with 'comp.object').

V
 
D

DeMarcus

Hi.
I have another design problem. I hope someone can help me. Thanks in
advance.

I want to write a "library" consisting in a bunch of objects like
Info, Utils, etc..

I made a member with each of these inside de main class (the
"library") and made the constructors private for Info, Utils, etc. and
made them friend classes of the main class.

Is this the right approach or should I use heritance from a base
class? I also need to access some of the methods in Utils from Info,
for instance, Format date function, trims, etc. etc. meaning that
utils will be accessible from outside the library and from within.

LIBRARY
|_ INFO
|_ UTILS
|_ etc.

Using a "main class" sounds wrong. Consider namespaces instead to
separate your library functionality. Take a look at www.boost.org. There
you can get all inspiration you need to write a professional library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top