473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1425
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
4031
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
7269
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
6596
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
6
2210
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
1887
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
2207
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
1454
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
2034
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
8912
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
8599
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
7254
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
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7094
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
7519
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...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
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...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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...

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.