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! 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
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!
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
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!
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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.
|
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...
|
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...
|
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...
| |
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...
|
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 .
|
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?
|
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;
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |