PC Review


Reply
Thread Tools Rate Thread

common practice for multiple object types in an arraylist?

 
 
Tarren
Guest
Posts: n/a
 
      17th May 2004
Hi:

I am writing a public function as part of a class and wanted to inquire as
to what is common practice to the following scenario.

I have a class called CARDEALERSHIP

i have two classes USEDCAR and NEWCAR both of which inherit CAR class

For the dealership, I have a property called INVENTORIEDCARS which returns
an ArrayList

since this inventory contains both USEDCAR objects and NEWCAR objects, would
i have the arraylist have objects of both types?

Then when I call an item in the arraylist, I would have to check the type
and carry out logic based on that?

How have people dealt with a scenario such as this?

Thanks all!


 
Reply With Quote
 
 
 
 
Lloyd Sheen
Guest
Posts: n/a
 
      17th May 2004
If there are many properties (I would think there would be) that USEDCAR and
NEWCAR both share then you might want to create a base class to hold those
properties. Then create those classes inheriting from lets say CAR which is
your base class.

Then you can do the following with INVENTORIEDCARS:

for each poCar as CAR in INVENTORIEDCARS

next

You will be assured (of course if you stored the correct objects) of getting
a list which could contain either USEDCAR or NEWCAR objects.

Now if the difference are not that great between the two classes you might
want to have a class that has all the details of CAR's and have a property
indicating whether the CAR was used or new.

If you cannot do this then within the for each loop above you can check the
typename of the poCar object returned and deal with it as required.

Lloyd Sheen

"Tarren" <noemailplease@thankyou> wrote in message
news:%(E-Mail Removed)...
> Hi:
>
> I am writing a public function as part of a class and wanted to inquire as
> to what is common practice to the following scenario.
>
> I have a class called CARDEALERSHIP
>
> i have two classes USEDCAR and NEWCAR both of which inherit CAR class
>
> For the dealership, I have a property called INVENTORIEDCARS which returns
> an ArrayList
>
> since this inventory contains both USEDCAR objects and NEWCAR objects,

would
> i have the arraylist have objects of both types?
>
> Then when I call an item in the arraylist, I would have to check the type
> and carry out logic based on that?
>
> How have people dealt with a scenario such as this?
>
> Thanks all!
>
>



 
Reply With Quote
 
Tarren
Guest
Posts: n/a
 
      17th May 2004
thanks!

"Lloyd Sheen" <(E-Mail Removed)> wrote in message
news:Pf7qc.47646$(E-Mail Removed)...
> If there are many properties (I would think there would be) that USEDCAR

and
> NEWCAR both share then you might want to create a base class to hold those
> properties. Then create those classes inheriting from lets say CAR which

is
> your base class.
>
> Then you can do the following with INVENTORIEDCARS:
>
> for each poCar as CAR in INVENTORIEDCARS
>
> next
>
> You will be assured (of course if you stored the correct objects) of

getting
> a list which could contain either USEDCAR or NEWCAR objects.
>
> Now if the difference are not that great between the two classes you might
> want to have a class that has all the details of CAR's and have a property
> indicating whether the CAR was used or new.
>
> If you cannot do this then within the for each loop above you can check

the
> typename of the poCar object returned and deal with it as required.
>
> Lloyd Sheen
>
> "Tarren" <noemailplease@thankyou> wrote in message
> news:%(E-Mail Removed)...
> > Hi:
> >
> > I am writing a public function as part of a class and wanted to inquire

as
> > to what is common practice to the following scenario.
> >
> > I have a class called CARDEALERSHIP
> >
> > i have two classes USEDCAR and NEWCAR both of which inherit CAR class
> >
> > For the dealership, I have a property called INVENTORIEDCARS which

returns
> > an ArrayList
> >
> > since this inventory contains both USEDCAR objects and NEWCAR objects,

> would
> > i have the arraylist have objects of both types?
> >
> > Then when I call an item in the arraylist, I would have to check the

type
> > and carry out logic based on that?
> >
> > How have people dealt with a scenario such as this?
> >
> > Thanks all!
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
What is common practice? Jim Franklin Microsoft Access Form Coding 12 23rd Sep 2007 12:39 AM
Common Practice to Connect SQL =?Utf-8?B?d3J5dGF0?= Microsoft ADO .NET 10 20th Jun 2007 04:48 PM
what is the common practice john Microsoft Access Database Table Design 1 27th May 2006 01:50 PM
Security most common practice Ben Microsoft Windows 2000 Active Directory 1 7th Apr 2006 08:57 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting Microsoft ASP .NET 0 29th Dec 2003 07:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 PM.