473,657 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RE: Two Classes with the same Data Structure.. saving code?Inheriting a structure?

jc
RE: Two Classes with the same Data Structure.. saving code? Inheriting
a structure?

I have two classes. One in Inherits System.Collecti ons.CollectionB ase,
the other does not, but they both have the identical structure and
properties. the only difference between them is there methods and that
one is a collection class and the other is not.

currently the code starts like this:

class1

Namespace WH
Public Class colCollaborator
Inherits System.Collecti ons.CollectionB ase
Public Structure s_Collaborator
Private m_Result As String
Private m_ColId As Integer
Private m_Lastname As String
Public Property ColId() As Integer
Get
Return m_ColId
End Get
Set(ByVal value As Integer)
m_ColId = value
End Set
End Property
... more code
class2
Namespace WH
Public Class Collaborator
Private m_ColId As Integer
Private m_Lastname As String
Private m_Firstname As String
Public Property ColId() As Integer
Get
Return m_ColId
End Get
Set(ByVal value As Integer)
m_ColId = value
End Set
End Property
....

Dumb noob question that I can't figure out despite endless resources..
is it possible to share or inherit that structure in both classes ..
and consolidate class files?

Thanks for any help or information!
Jun 27 '08 #1
5 1551
On 12 Jun., 21:11, jc <wild...@noclie nt.netwrote:
RE: Two Classes with the same Data Structure.. saving code? Inheriting
a structure?

I have two classes. One in Inherits System.Collecti ons.CollectionB ase,
the other does not, but they both have the identical structure and
properties. the only difference between them is there methods and that
one is a collection class and the other is not.
Just two thoughts:

You could use an abstract class to do this. Look here:
http://www.devx.com/dotnet/Article/28086 You could also use
inheritance although they say "use aggregation, not inheritance".
At least it would be a good idea to create an interface and implement
it in your two classes.

Michael

Jun 27 '08 #2
jc
But then wouldn't this be true?

quote -

All types that implement the AnInterface interface must implement
every declared method in that interface. In this example we only need
to implement the function WhoAmI. Suppose AClass implements
AnInterface; we would need to implement WhoAmI. The result of
implement AnInterface in AClass would yield the following code.

Public Class AClass
Implements AnInterface

Public Function WhoAmI() As String Implements AnInterface.Who AmI
Return "AClass"
End Function

End Class

endquote -
I'll try it out.. but if anybody has a simple example of how to reuse
the structure code in two classes where one class is already
inheriting another class (understanding that vb does not support
multiple inheritances). Any help is appreciated.

Thank you!
Jun 27 '08 #3
jc wrote:
RE: Two Classes with the same Data Structure.. saving code? Inheriting
a structure?

I have two classes. One in Inherits System.Collecti ons.CollectionB ase,
the other does not, but they both have the identical structure and
properties. the only difference between them is there methods and that
one is a collection class and the other is not.

currently the code starts like this:

class1

Namespace WH
Public Class colCollaborator
Inherits System.Collecti ons.CollectionB ase
Public Structure s_Collaborator
Private m_Result As String
Private m_ColId As Integer
Private m_Lastname As String
Public Property ColId() As Integer
Get
Return m_ColId
End Get
Set(ByVal value As Integer)
m_ColId = value
End Set
End Property
... more code
class2
Namespace WH
Public Class Collaborator
Private m_ColId As Integer
Private m_Lastname As String
Private m_Firstname As String
Public Property ColId() As Integer
Get
Return m_ColId
End Get
Set(ByVal value As Integer)
m_ColId = value
End Set
End Property
....

Dumb noob question that I can't figure out despite endless resources..
is it possible to share or inherit that structure in both classes ..
and consolidate class files?

Thanks for any help or information!
Do you absolutely need the colCollaborator class to inherit the
CollectionBase class? Otherwise you can just remove that inheritance,
and make the colCollaborator class inherit the Collaborator class. You
can quite easily implement things like IEnumerable if you need to
iterate a collection in the class.

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #4
jc
On Jun 13, 5:22 pm, Göran Andersson <gu...@guffa.co mwrote:
jc wrote:
RE: Two Classes with the same Data Structure.. saving code? Inheriting
a structure?
I have two classes. One in Inherits System.Collecti ons.CollectionB ase,
the other does not, but they both have the identical structure and
properties. the only difference between them is there methods and that
one is a collection class and the other is not.
currently the code starts like this:
class1
Namespace WH
Public Class colCollaborator
Inherits System.Collecti ons.CollectionB ase
Public Structure s_Collaborator
Private m_Result As String
Private m_ColId As Integer
Private m_Lastname As String
Public Property ColId() As Integer
Get
Return m_ColId
End Get
Set(ByVal value As Integer)
m_ColId = value
End Set
End Property
... more code
class2
Namespace WH
Public Class Collaborator
Private m_ColId As Integer
Private m_Lastname As String
Private m_Firstname As String
Public Property ColId() As Integer
Get
Return m_ColId
End Get
Set(ByVal value As Integer)
m_ColId = value
End Set
End Property
....
Dumb noob question that I can't figure out despite endless resources..
is it possible to share or inherit that structure in both classes ..
and consolidate class files?
Thanks for any help or information!

Do you absolutely need the colCollaborator class to inherit the
CollectionBase class? Otherwise you can just remove that inheritance,
and make the colCollaborator class inherit the Collaborator class. You
can quite easily implement things like IEnumerable if you need to
iterate a collection in the class.

--
Göran Andersson
_____http://www.guffa.com
Göran,

Can you show me a simple example ? I'm somewhat new to OOP.

Very interested in see that.

Thank you!
Jun 27 '08 #5
jc wrote:
>

I'll try it out.. but if anybody has a simple example of how to reuse
the structure code in two classes where one class is already
inheriting another class (understanding that vb does not support
multiple inheritances). Any help is appreciated.
I'm not sure what you are really after, but I would probably do it by embedding
a Collaborator object inside of colCollaborator . This is sometimes referred to
as "aggregatin g" a class within another class.

Public Class Collaborator
Private m_ColId As Integer
' ...
Public Property ColId() As Integer
' ...
End Property
' ...
End Class

Public Class colCollaborator
Inherits System.Collecti ons.CollectionB ase
Private m_Collab As Collaborator
' ...
Public ReadOnly Property Collab As Collaborator
Get
Return m_Collab
End Get
End Property
' ...
End Class

The effect is that colCollaborator is a collection, but also has a .Collab
property, which reveals all the properties of a Collaborator object as well.

Jun 27 '08 #6

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

Similar topics

45
3593
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes themselves are an exception to this), and 'bootstrap' your program by instantiating a single application object in main(), would that place any limitations on what you could accomplish with your program? Are there any benefits to doing things that...
2
2228
by: Peter Bates | last post by:
Hi, I'm just getting used to XSDObjectGen and i have the following question. Can i use a class inherited from a class generated by XSDObjectGen with XmlSerialize? Specifically, I have many xml files arriving from a PC inventory scanner we use. I wish to deserialize them and then process them.
4
3547
by: Chuck Bowling | last post by:
I am using CodeDOM to generate source files. The classes being generated have a const string member. This member is referenced in an abstract base class but declared in the inheriting class. I can't declare the string in the abstract class because it would require initialization. Is there a way to require that any class inheriting from the base class contain this string without a specific declaration in the base class? I tried putting a...
6
4481
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler systems over the years. I have developed code in more than 30 distinct programming languages for a wide cariety of industries. But this issue of structures in C# is beginning to annoy me. I should also make it clear that I am not a big supporter...
6
1575
by: David Lozzi | last post by:
Howdy, I'm new to classes. Below is my class User. (is this a reserved namespace or class?) It works great, kind of. If I specify the username and password, the correct firstname and lastname are returned. For example, username dlozzi, password fun. It returns David Lozzi as full name. If I login as someone else on another computer, say username dsmith and password fun2, the second computer displays the correct fullname. HOWEVER if I...
11
2341
by: aaragon | last post by:
Hi everyone. I'm trying to write a class with policy based design (Alexandrescu's Modern C++ Design). I'm not a programmer but an engineer so this is kind of hard for me. Through the use of policies, I want to customize the structure of a class. The idea is to investigate the use of several data structures. One option would be the use of the boost dynamic bitset. Another would be the use of the std::vector. I obtained some code that...
7
2495
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
29
2760
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much overhead (I think). A Struct seems more appropriate. At least it is what I would have used in other languages. But since a Struct *can* hold methods, I wander if I am saving anything. If not, why use it?
7
3125
by: ademirzanetti | last post by:
Hi there !!! I would like to listen your opinions about inherit from a STL class like list. For example, do you think it is a good approach if I inherit from list to create something like "myList" as in the example below ? #include "Sector.h" using namespace boost;
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.