473,238 Members | 1,799 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.

Interface vs Struct

I am new to object oriented design. I am using VS 2005. I was going to
create three classes then have those classes inherited by one class but c#
does not support multiple inheritance. My three base classes would have
properties only and no methods. What would be best to use in this case an
interface or struct or something else?

When adding items to the project I did not see a template for struct or for
an interface, but there is a template for class (.cs).

Originally I had planned to have three base classes:
Owner class, Property Class and Value Class

And a PropertyHistory class that would inherit all the base classes and
PropertyHistory could be added to a collection so I could iterate through it
and sort it.

I wanted the base classes to be reused separately in other areas of the
application.

What is the best way to do this?

--
Happy In SoAz
Jun 27 '08 #1
7 1831
SoAzAppDever wrote:
I am new to object oriented design. I am using VS 2005. I was going to
create three classes then have those classes inherited by one class but c#
does not support multiple inheritance. My three base classes would have
properties only and no methods. What would be best to use in this case an
interface or struct or something else?
Neither interface or struct solves that problem.

I think you need to make the one class have a reference to the
3 "base" classes instead of inheriting.

Arne
Jun 27 '08 #2
So In the PropertyHistory class I could pass in the three base classes like so

class PropertyHistory(Owner oObj, Property oProp, Value oVal)
{
do stuff
}

?

--
Happy In SoAz
"Arne Vajhøj" wrote:
SoAzAppDever wrote:
I am new to object oriented design. I am using VS 2005. I was going to
create three classes then have those classes inherited by one class but c#
does not support multiple inheritance. My three base classes would have
properties only and no methods. What would be best to use in this case an
interface or struct or something else?

Neither interface or struct solves that problem.

I think you need to make the one class have a reference to the
3 "base" classes instead of inheriting.

Arne
Jun 27 '08 #3
"SoAzAppDever" <So**********@discussions.microsoft.comwrote in message
news:3B**********************************@microsof t.com...
So In the PropertyHistory class I could pass in the three base classes
like so

class PropertyHistory(Owner oObj, Property oProp, Value oVal)
{
do stuff
}

?

"Arne Vajhj" wrote:
>SoAzAppDever wrote:
I am new to object oriented design. I am using VS 2005. I was going
to
create three classes then have those classes inherited by one class but
c#
does not support multiple inheritance. My three base classes would
have
properties only and no methods. What would be best to use in this case
an
interface or struct or something else?

Neither interface or struct solves that problem.

I think you need to make the one class have a reference to the
3 "base" classes instead of inheriting.

Arne
Arne means that since PropertyHistory is not a Property, nor is it a Owner,
nor is it a Value, it won't inherit from any of them. An instance of
PropertyHistory will have references to an instance of Property, an instance
of Owner, and an instance of Value.

AHS
Jun 27 '08 #4
I am not sure I understand. Can you show me in code? What is have done is
the following:

public class ParcelHistory
{
//members
private Owner _owner;
private Property _property;
private Value _value;
//contructor
public PropertyHistory(Owner owner, Property property, Value value)
{
_owner = owner;
_property = property;
_value = value;
}

//properties
public Owner HistoryOwner
{
get { return _owner; }
}

public Property HistoryProperty
{
get { return _property; }
}

public Value HistoryValue
{
get { return _value; }
}

}
--
Happy In SoAz
"Arved Sandstrom" wrote:
"SoAzAppDever" <So**********@discussions.microsoft.comwrote in message
news:3B**********************************@microsof t.com...
So In the PropertyHistory class I could pass in the three base classes
like so

class PropertyHistory(Owner oObj, Property oProp, Value oVal)
{
do stuff
}

?

"Arne Vajhøj" wrote:
SoAzAppDever wrote:
I am new to object oriented design. I am using VS 2005. I was going
to
create three classes then have those classes inherited by one class but
c#
does not support multiple inheritance. My three base classes would
have
properties only and no methods. What would be best to use in this case
an
interface or struct or something else?

Neither interface or struct solves that problem.

I think you need to make the one class have a reference to the
3 "base" classes instead of inheriting.

Arne

Arne means that since PropertyHistory is not a Property, nor is it a Owner,
nor is it a Value, it won't inherit from any of them. An instance of
PropertyHistory will have references to an instance of Property, an instance
of Owner, and an instance of Value.

AHS
Jun 27 '08 #5
Arved Sandstrom wrote:
"SoAzAppDever" <So**********@discussions.microsoft.comwrote in message
news:3B**********************************@microsof t.com...
>"Arne Vajhj" wrote:
>>SoAzAppDever wrote:
I am new to object oriented design. I am using VS 2005. I was going
to
create three classes then have those classes inherited by one class but
c#
does not support multiple inheritance. My three base classes would
have
properties only and no methods. What would be best to use in this case
an
interface or struct or something else?
Neither interface or struct solves that problem.

I think you need to make the one class have a reference to the
3 "base" classes instead of inheriting.
So In the PropertyHistory class I could pass in the three base classes
like so

class PropertyHistory(Owner oObj, Property oProp, Value oVal)
{
do stuff
}

?

Arne means that since PropertyHistory is not a Property, nor is it a Owner,
nor is it a Value, it won't inherit from any of them. An instance of
PropertyHistory will have references to an instance of Property, an instance
of Owner, and an instance of Value.
Yup.

3 x "has a" instead of the invalid 3 x "is a".

Arne
Jun 27 '08 #6
As Arne suggest..

Inheritance represents an IS_A relationship from a generalization to a
specialization. Containment represents a HAS_A relationship between the
whole and a part. So a car IS_A motorized vehicle, but HAS_A radio. The
two
relationships can be expressed in code (text view) thusly:

class Radio
{
...
}
class Vehicle
{
...
}
class Car : Vehicle
{
Radio r= new Radio();
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #7
Thank you that is very helpful!
--
Happy In SoAz
"Jeff Louie" wrote:
As Arne suggest..

Inheritance represents an IS_A relationship from a generalization to a
specialization. Containment represents a HAS_A relationship between the
whole and a part. So a car IS_A motorized vehicle, but HAS_A radio. The
two
relationships can be expressed in code (text view) thusly:

class Radio
{
...
}
class Vehicle
{
...
}
class Car : Vehicle
{
Radio r= new Radio();
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #8

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

Similar topics

17
by: Zytan | last post by:
Aren't all classes interfaces? What constitutes an interface (and with it, the "I" prefix distinction)? Zytan
3
by: goodmen | last post by:
I think the boost::concept_check is too complex. Here is my solution about static interface and concept. The static interface can be used as function param. It is just a proxy of the real...
1
by: yadolov | last post by:
I have COM-object with Iface interface: typedef struct { .... } TStruct; interface Iface : IUnknown {
6
by: Chris Carlen | last post by:
Hi: I have an embedded system, platform: TI TMS320F2812 32-bit integer DSP. A module (.c file) contains external (to the funcs in that module) variables which are used to affect the operation...
1
by: recherche | last post by:
Hola! I tried the following public implementation of interface indexer by struct (Code Snippet 1) in private and explicit implementation by struct (Code Snippet 2) but in vain. Please help! ...
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
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
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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.