473,238 Members | 1,563 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,238 software developers and data experts.

Class structure questio n ???

Dear all

I have an Object that I will call for instance VEHICULE. This object
contains some other type of objects like CAR and BICYCLE

VEHICULE has necessary at least one object of type CAR or BYCICLE

My question is that if I am at the VEHICLE lass level, it can contains a
certain amount of CAR class and BICYCLE class.

What is the best way to handle the content of VEHICLE, is it good to handle
a List of object of other type like as follow:

public class VEHICULE

dim ListOFCar as system.collection.Arrays
dim ListOFBycicle as system.collection.Arrays

class CAR
.....
end class

class BYCICLE
...
end class

end class

is it correct or there is a better way like Inheritence ?

thnaks for your help
regards
serge
Jul 21 '05 #1
4 1353
Serge,

A vehicle has mostly wheels (A car mostly four a Bicycle mostly two), so for
the wheels you can take an collection of wheels.

However a Car and a Bicycle would in my way inherid from verhickle.

For steering has a Car a simple wheel so that needs probably not to be
overriden.

A Bicycle has a handle-bar that contains a lot of properties itself, so that
should override the steering from the verhicle.

However a bicycle has no engine, so that can be shadowed (your showed code
is VBnet), with by instance setting it consequently to nothing or by
throwing an exception).

Just my idea,

Cor
Jul 21 '05 #2
Serge, i'm not sure i understand your question so let me tell you what i
think you're saying. You have several different types of vehicles such as
cars and bicycles. You also have a collection that will contain a mixture of
different types of vehicles

If that is true, your collection should hold objects of one type. Any object
in that collection would want to either inherit from that type or implement
an interface of that type. An example:

public class Vehicle
{
protected string name;
}
public class Car : Vehicle
{
public Car(string name) { this.name = name; }
}
public class Bicycle : Vehicle
{
public Bicycle(string name) { this.name = name; }
}
public class Vehicles
{
ArrayList collection = new ArrayList();
public void add(Vehicle aVehicle) { collection.Add(aVehicle); }
}

Your Application
Vehicles myGarage = new Vehicles();
myGarage.add(new Car("Ferrari"));
myGarage.add(new Bicycle("Schwinn"));

When you get the values back, they'll be of type Vehicle, not Car or
Bicycle. If you want to turn them back into that, you can recast it

Vehicle myVehicle = (Vehicle) collection[1];
if (myVehicle is Car)
{
Car myCar = (Car) collection[1];
}
else if (myVehicle is Bicycle)
{
Bicycle myBike = (Bicycle) collection[1];
}

Hope that's what you were looking for

-baylor
Jul 21 '05 #3
HI,

thnaks for zour reply, it helps partly

In fact I was wondering if the classes Bicycle and car should be defined
as nested class of vehicule or outside.

If they are netsed class from vehicule is there a way that class vehicule
access data of it nested class? same thing in reverse is they a way that
nested class can access to meber of parent class ?

is also a way to doit without using interface or inheritance, or is it
something impossible. In fact I try to see what would be the different if I
use nested class

regards
serge

"baylor" wrote:
Serge, i'm not sure i understand your question so let me tell you what i
think you're saying. You have several different types of vehicles such as
cars and bicycles. You also have a collection that will contain a mixture of
different types of vehicles

If that is true, your collection should hold objects of one type. Any object
in that collection would want to either inherit from that type or implement
an interface of that type. An example:

public class Vehicle
{
protected string name;
}
public class Car : Vehicle
{
public Car(string name) { this.name = name; }
}
public class Bicycle : Vehicle
{
public Bicycle(string name) { this.name = name; }
}
public class Vehicles
{
ArrayList collection = new ArrayList();
public void add(Vehicle aVehicle) { collection.Add(aVehicle); }
}

Your Application
Vehicles myGarage = new Vehicles();
myGarage.add(new Car("Ferrari"));
myGarage.add(new Bicycle("Schwinn"));

When you get the values back, they'll be of type Vehicle, not Car or
Bicycle. If you want to turn them back into that, you can recast it

Vehicle myVehicle = (Vehicle) collection[1];
if (myVehicle is Car)
{
Car myCar = (Car) collection[1];
}
else if (myVehicle is Bicycle)
{
Bicycle myBike = (Bicycle) collection[1];
}

Hope that's what you were looking for

-baylor

Jul 21 '05 #4
Serge,

In my opinion is in this article everything you ask for.

http://msdn.microsoft.com/library/de...assinherit.asp

I hope this helps,

Cor
Jul 21 '05 #5

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

Similar topics

1
by: Victor Hannak | last post by:
I have two classes derived from a base class. The two derived classes each utilize a structure that is slightly different from one another. i.e. DerivedClass1: struct NodeStruct { float...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
3
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user...
4
by: serge calderara | last post by:
Dear all I have an Object that I will call for instance VEHICULE. This object contains some other type of objects like CAR and BICYCLE VEHICULE has necessary at least one object of type CAR or...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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...

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.