473,405 Members | 2,379 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,405 software developers and data experts.

class properties

TS
i have a question about this situation:

i have a class that i use that i need to know 1 piece of data that exists in
a different class. Im wondering is it wrong to add the property that i need
onto the first class instead of having to instantiate the whole other class
for a single property?

If it isn't bad, where would you draw the line on what duplicated properties
you have?

thanks for the insight
Nov 17 '05 #1
12 1421
Is class inheritance the right answer?

public class MyClass : MyNameSpace.MyOtherClass
{
}

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"TS" <ma**********@nospam.nospam> wrote in message
news:e1**************@TK2MSFTNGP15.phx.gbl...
i have a question about this situation:

i have a class that i use that i need to know 1 piece of data that exists
in
a different class. Im wondering is it wrong to add the property that i
need
onto the first class instead of having to instantiate the whole other
class
for a single property?

If it isn't bad, where would you draw the line on what duplicated
properties
you have?

thanks for the insight

Nov 17 '05 #2
Is class inheritance the right answer?

public class MyClass : MyNameSpace.MyOtherClass
{
}

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"TS" <ma**********@nospam.nospam> wrote in message
news:e1**************@TK2MSFTNGP15.phx.gbl...
i have a question about this situation:

i have a class that i use that i need to know 1 piece of data that exists
in
a different class. Im wondering is it wrong to add the property that i
need
onto the first class instead of having to instantiate the whole other
class
for a single property?

If it isn't bad, where would you draw the line on what duplicated
properties
you have?

thanks for the insight

Nov 17 '05 #3
Could you be more specific? The situation you described could apply to
so many different things, it's hard to know what advice to give.

Nov 17 '05 #4
Hi TS,

Thanks for your post.

Yes, I think if there are not too many properties we want to get from
class2 and these properties are not very hard to implement in class1, we
can just create a duplicated property for class1 usage.

However, if in OOP, we want to expose a number of properties from class2 to
class1, I think composition or inheritance can be considered. To determine
whether or not to use composition/inheritance or just duplicate property
definition, we can judge from the class relation semantics. If in logic
class2 is a part feature of class1, composition should be a suitable
choice, and we can use expose the wanted class2 properties as properties of
class1. If in logic class1 is a specific type of class2, we can just
inherit from class2 to create class1, then in class1 we can get the
properties of class2 without any problem.

Hope this helps
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5
Could you be more specific? The situation you described could apply to
so many different things, it's hard to know what advice to give.

Nov 17 '05 #6
Hi TS,

Thanks for your post.

Yes, I think if there are not too many properties we want to get from
class2 and these properties are not very hard to implement in class1, we
can just create a duplicated property for class1 usage.

However, if in OOP, we want to expose a number of properties from class2 to
class1, I think composition or inheritance can be considered. To determine
whether or not to use composition/inheritance or just duplicate property
definition, we can judge from the class relation semantics. If in logic
class2 is a part feature of class1, composition should be a suitable
choice, and we can use expose the wanted class2 properties as properties of
class1. If in logic class1 is a specific type of class2, we can just
inherit from class2 to create class1, then in class1 we can get the
properties of class2 without any problem.

Hope this helps
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7
TS
Thanks, I didn't know what the word composition meant. Now that i do, i know
that this is the method employed in the project i am working on....which
brings me back to my original question:

if you use composition, and access a property from class2 that simply points
to class1, you have to load class1 to access the property you are actually
interested in. This is how you can access a property of class1 from class2.
The thing is is that you have to load the whole class to access that single
property.

I can see that is good OOP, just wondering what your thoughts were,

thanks Jeffrey!

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:Rl*************@TK2MSFTNGXA01.phx.gbl...
Hi TS,

Thanks for your post.

Yes, I think if there are not too many properties we want to get from
class2 and these properties are not very hard to implement in class1, we
can just create a duplicated property for class1 usage.

However, if in OOP, we want to expose a number of properties from class2 to class1, I think composition or inheritance can be considered. To determine
whether or not to use composition/inheritance or just duplicate property
definition, we can judge from the class relation semantics. If in logic
class2 is a part feature of class1, composition should be a suitable
choice, and we can use expose the wanted class2 properties as properties of class1. If in logic class1 is a specific type of class2, we can just
inherit from class2 to create class1, then in class1 we can get the
properties of class2 without any problem.

Hope this helps
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #8
TS
Thanks, I didn't know what the word composition meant. Now that i do, i know
that this is the method employed in the project i am working on....which
brings me back to my original question:

if you use composition, and access a property from class2 that simply points
to class1, you have to load class1 to access the property you are actually
interested in. This is how you can access a property of class1 from class2.
The thing is is that you have to load the whole class to access that single
property.

I can see that is good OOP, just wondering what your thoughts were,

thanks Jeffrey!

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:Rl*************@TK2MSFTNGXA01.phx.gbl...
Hi TS,

Thanks for your post.

Yes, I think if there are not too many properties we want to get from
class2 and these properties are not very hard to implement in class1, we
can just create a duplicated property for class1 usage.

However, if in OOP, we want to expose a number of properties from class2 to class1, I think composition or inheritance can be considered. To determine
whether or not to use composition/inheritance or just duplicate property
definition, we can judge from the class relation semantics. If in logic
class2 is a part feature of class1, composition should be a suitable
choice, and we can use expose the wanted class2 properties as properties of class1. If in logic class1 is a specific type of class2, we can just
inherit from class2 to create class1, then in class1 we can get the
properties of class2 without any problem.

Hope this helps
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #9
Hi TS,

Thanks for your feedback.

I am not sure I express myself clear in the last reply. Yes, composition is
a common way to use in this scenario, and we usually use this way.
However, this is not the only way, if the number of properties we want
expose from class1 is very large, we can just re-implement these wanted
properties in class2 without class1 knowing about. I think this will reduce
a lot of space, performance etc.., if in OOP semantics, the class1 should
be part feature of class2, I think your way of using composition(that is
create a class1 instance in class2) is the best choice.

Note: there may be some properties that is hard to re-implement out of the
scope of class1, in this situation, I think we have to use composition.

Also, I suggest you read my last reply again to gain a better understanding
of my comment. If you still have any concern, please feel free to tell me,
thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #10
Hi TS,

Does my reply make sense to you? If you still have any concern, please feel
free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #11
TS
sounds good, thanks

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:mU**************@TK2MSFTNGXA01.phx.gbl...
Hi TS,

Does my reply make sense to you? If you still have any concern, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #12
You are welcome :-)

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #13

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

Similar topics

21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
5
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
6
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base...
16
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
2
by: mgoold2002 | last post by:
Hello. I've just begun programming in VB .NET, and I'm trying to turn all my modules into classes. In order to retrieve/exchange values from one class to another, I initiated New instances of the...
3
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
5
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.