473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Inheritance/BaseClass

Ok,

here is another question I have that is sort of unrelated to my last
posting about composition.

I have three Collection classes:
EmployeeCollection
HourCollection
InfractionCollection

all three of these classes inherit from ArrayList and will have
Add/Item/Remove methods.

I noticed in the documentation that in the arraylist class, the Item
method returns an object. Would I override the Item method to return
the correct type of class. Then i run into the problem that I notice
that the Add method of the arraylist class takes an input parameter of
type object, so would i also need to override this method to pass the
specific class type that i want to add to the arraylist or would I
just add an item to the arraylist as type object and then cast it to
the particular type when I use the Item method?
I have another example of the following classes:
Hour
Infraction

these two classes will share quite a few identical methods such as:
AddHour, AddInfraction, EditHour, EditInfraction etc..

I have created a base class for these two classes called HIDetailBase
which will contain the Add, Edit methods, now I am in the same boat as
my first question, what is the proper way to override/overload the
methods to get the functionality i require.

Any help would be greatly appreciated. thank you
Jul 21 '05 #1
8 1378
As I see it, you have 3 choices:

1. Just use an ArrayList and be done with it. May not be possible if your
class has a lot of extra functionality.

2. Derive from ArrayList, but don't ceate your own functions for Add and
Remove, or any other methods provided by ArrayList. If you add new methods
for Add and Remove, the original ArrayList methods will still be visible to
the users of your class, and this could cause confusion, and bugs.

3. Don't derive from ArrayList, simple have your class contain an ArrayList.
Then write your Add, Remove, ... with correctly typed arguments instead of
Object.

Personally, I wou do option 1 or 3, depending on whether your class is
simply a collection, or has other enhanced functionality.
"DKode" <dk***@cfl.rr.com> wrote in message
news:b1**************************@posting.google.c om...
Ok,

here is another question I have that is sort of unrelated to my last
posting about composition.

I have three Collection classes:
EmployeeCollection
HourCollection
InfractionCollection

all three of these classes inherit from ArrayList and will have
Add/Item/Remove methods.

I noticed in the documentation that in the arraylist class, the Item
method returns an object. Would I override the Item method to return
the correct type of class. Then i run into the problem that I notice
that the Add method of the arraylist class takes an input parameter of
type object, so would i also need to override this method to pass the
specific class type that i want to add to the arraylist or would I
just add an item to the arraylist as type object and then cast it to
the particular type when I use the Item method?
I have another example of the following classes:
Hour
Infraction

these two classes will share quite a few identical methods such as:
AddHour, AddInfraction, EditHour, EditInfraction etc..

I have created a base class for these two classes called HIDetailBase
which will contain the Add, Edit methods, now I am in the same boat as
my first question, what is the proper way to override/overload the
methods to get the functionality i require.

Any help would be greatly appreciated. thank you

Jul 21 '05 #2
ms-help://MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionscollectio
nbaseclasstopic.htm
public abstract class CollectionBase : IList, ICollection,
IEnumerable
Cant you just use CollectionBase and roll yer own using ArrayList?

"Michael Bird" <birdm @ symbol . com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
As I see it, you have 3 choices:

1. Just use an ArrayList and be done with it. May not be possible if your class has a lot of extra functionality.

2. Derive from ArrayList, but don't ceate your own functions for Add and
Remove, or any other methods provided by ArrayList. If you add new methods for Add and Remove, the original ArrayList methods will still be visible to the users of your class, and this could cause confusion, and bugs.

3. Don't derive from ArrayList, simple have your class contain an ArrayList. Then write your Add, Remove, ... with correctly typed arguments instead of
Object.

Personally, I wou do option 1 or 3, depending on whether your class is
simply a collection, or has other enhanced functionality.
"DKode" <dk***@cfl.rr.com> wrote in message
news:b1**************************@posting.google.c om...
Ok,

here is another question I have that is sort of unrelated to my last
posting about composition.

I have three Collection classes:
EmployeeCollection
HourCollection
InfractionCollection

all three of these classes inherit from ArrayList and will have
Add/Item/Remove methods.

I noticed in the documentation that in the arraylist class, the Item
method returns an object. Would I override the Item method to return
the correct type of class. Then i run into the problem that I notice
that the Add method of the arraylist class takes an input parameter of
type object, so would i also need to override this method to pass the
specific class type that i want to add to the arraylist or would I
just add an item to the arraylist as type object and then cast it to
the particular type when I use the Item method?
I have another example of the following classes:
Hour
Infraction

these two classes will share quite a few identical methods such as:
AddHour, AddInfraction, EditHour, EditInfraction etc..

I have created a base class for these two classes called HIDetailBase
which will contain the Add, Edit methods, now I am in the same boat as
my first question, what is the proper way to override/overload the
methods to get the functionality i require.

Any help would be greatly appreciated. thank you


Jul 21 '05 #3
I think what I will end up doing is create collection base classes
that derive from system.collections.collectionbase as I used this for
another app i worked on. This will allow my collections to be scalable
in the future as I think they will be. I setup composition
associations in my Static structure diagram between the HourCollection
and InfractionCollection classes and my Employee class. I then have
methods in my Employee class that will get the proper information from
the database and populate the collection classes that are associated
with the employee class.

does this sound correct?
<di********@discussion.microsoft.com> wrote in message news:<Ou**************@TK2MSFTNGP09.phx.gbl>...
ms-help://MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionscollectio
nbaseclasstopic.htm
public abstract class CollectionBase : IList, ICollection,
IEnumerable
Cant you just use CollectionBase and roll yer own using ArrayList?

"Michael Bird" <birdm @ symbol . com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
As I see it, you have 3 choices:

1. Just use an ArrayList and be done with it. May not be possible if

your
class has a lot of extra functionality.

2. Derive from ArrayList, but don't ceate your own functions for Add and
Remove, or any other methods provided by ArrayList. If you add new

methods
for Add and Remove, the original ArrayList methods will still be visible

to
the users of your class, and this could cause confusion, and bugs.

3. Don't derive from ArrayList, simple have your class contain an

ArrayList.
Then write your Add, Remove, ... with correctly typed arguments instead of
Object.

Personally, I wou do option 1 or 3, depending on whether your class is
simply a collection, or has other enhanced functionality.
"DKode" <dk***@cfl.rr.com> wrote in message
news:b1**************************@posting.google.c om...
Ok,

here is another question I have that is sort of unrelated to my last
posting about composition.

I have three Collection classes:
EmployeeCollection
HourCollection
InfractionCollection

all three of these classes inherit from ArrayList and will have
Add/Item/Remove methods.

I noticed in the documentation that in the arraylist class, the Item
method returns an object. Would I override the Item method to return
the correct type of class. Then i run into the problem that I notice
that the Add method of the arraylist class takes an input parameter of
type object, so would i also need to override this method to pass the
specific class type that i want to add to the arraylist or would I
just add an item to the arraylist as type object and then cast it to
the particular type when I use the Item method?
I have another example of the following classes:
Hour
Infraction

these two classes will share quite a few identical methods such as:
AddHour, AddInfraction, EditHour, EditInfraction etc..

I have created a base class for these two classes called HIDetailBase
which will contain the Add, Edit methods, now I am in the same boat as
my first question, what is the proper way to override/overload the
methods to get the functionality i require.

Any help would be greatly appreciated. thank you


Jul 21 '05 #4
dk***@cfl.rr.com (DKode) wrote in
news:b1**************************@posting.google.c om:
I think what I will end up doing is create collection base classes
that derive from system.collections.collectionbase as I used this for
another app i worked on. This will allow my collections to be scalable
in the future as I think they will be. I setup composition
associations in my Static structure diagram between the HourCollection
and InfractionCollection classes and my Employee class. I then have
methods in my Employee class that will get the proper information from
the database and populate the collection classes that are associated
with the employee class.

does this sound correct?


YES. Use CollectionBase. I have some examples and a generator to make
your own custom collections based on my examples (templates). Feel free to
use one of them.

This is open source, and free of charge...
http://sourceforge.net/projects/colcodegen

Most of my templates allow for indexing by more than just index, but by
some kind of key (string, int, or guid). If you don't want the extra
indexing, just delete the unneeded sections.

Michael Lang, MCSD
Jul 21 '05 #5
Hi DKode, Michael,

There is another choice to go with the first 3:

4. Derive from ArrayList. Implement your own Add, AddRange,
etc - anything that you want strongly typed. Leave everything else
for ArrayList to handle. Override the ArrayList Add, AddRange,
etc, which use Object - but leave them empty and make them private.

Regards,
Fergus
Jul 21 '05 #6
Hello,

Excuse me for sounding like a newb, but what do you mean by strongly typed?

thanks

"Fergus Cooney" <fi****@post.com> wrote in message news:<e1**************@TK2MSFTNGP11.phx.gbl>...
Hi DKode, Michael,

There is another choice to go with the first 3:

4. Derive from ArrayList. Implement your own Add, AddRange,
etc - anything that you want strongly typed. Leave everything else
for ArrayList to handle. Override the ArrayList Add, AddRange,
etc, which use Object - but leave them empty and make them private.

Regards,
Fergus

Jul 21 '05 #7
dk***@cfl.rr.com (DKode) wrote in
news:b1**************************@posting.google.c om:
Excuse me for sounding like a newb, but what do you mean by strongly
typed?


It means the most relevant derived type instead of a base class type (such
as "Object" - everything ultimately derives from object).

Michael Lang
Jul 21 '05 #8
Hi Michael, DKode

Thanks, Michael.

|| anything that you want strongly typed

Yes, I should have written

'anything that you want strongly typed (ie. in your own type)'.

Regards,
Fergus
Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jürgen Kaminski | last post by:
Hello all, I got some legacy code where a template implements a non-templated interface. These classes are really HUGE, but it boils down to the following structure: class BaseClass { public:...
5
by: rkozlin | last post by:
Running into an issue where the compiler will throw an error... "The type '<BaseClass>' is defined in an assembly that is not referenced. You must add a reference to assembly '<BaseClass>'." ...
9
by: MSDNAndi | last post by:
Hi, I have the following problem with VS 2005 (Professional) and C# 2.0 I will use assembly and namespace synonymously here. I have a class in namespace InheritClass inherit from a baseclass...
10
by: KraftDiner | last post by:
I have two classes: class implicitClass: def __init__(self): def isIVR(self): #This is a class private method. def fromfile(self, fileObj, byteOrder): def getVR(self): def getGroup(self):...
3
by: ernesto | last post by:
Hi everybody I have the following class declarations: class Interface { public: virtual char* getName() const = 0; }; class BaseClass : public Interface {
2
by: Michael | last post by:
Hi All, I have the following: #include <iostream> class BaseClass { protected: int var; public:
8
by: RSH | last post by:
Hi, I am working on some general OOP constructs and I was wondering if I could get some guidance. I have an instance where I have a Base Abstract Class, and 4 Derived classes. I now need to...
1
by: Eric | last post by:
Let's say I have a base class that implements IComparable<baseClass>. Really it could be any interface but I'm picking that one for the sake of discussion. In this class, equality and comparisons...
11
by: Simon Woods | last post by:
Hi I have this recursive function and I want to walk the inheritance hierarchy to set field values .... the generic T is constrainted as the base class of the inheritance hierarchy Friend...
4
by: Sid Price | last post by:
I have a problem with my class hierarchy at runtime and would appreciate some input. I have a base class, let's call it "BaseClass", that has a public function "ToXML". In BaseClass.ToXML some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.