471,599 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 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 1361
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Jon Slaughter | last post: by
16 posts views Thread by Dennis | last post: by
9 posts views Thread by David A. Osborn | last post: by
8 posts views Thread by Per Bull Holmen | last post: by
5 posts views Thread by Rainer Queck | last post: by
2 posts views Thread by XIAOLAOHU | last post: by

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.