Re: Is it good programming to set instance in class without using C-tor
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Wed, 06 Sep 2006 17:02:21 -0400
Tony Johansson wrote:
I have a class definition called MyClass see below.
I create an instance of this class MyClass
I also want this instance to be able to modify the test instance that exist in this class.
I can make the instance of this class MyClass to be able to access the instance test in two ways.
I can either pass an instance of this class MyClass in the c-tor and assign the instance to the test field.
I can also use a set property by calling the property. Here I set an instance to the test field.
In general I prefer both:
- no arg constructor + property setter
- constructor with args
But in your specific case (where the property is the same
type as the class itself) I think you can not pass
the arg in the constructor or you will get an infinite
source code (unless you have another way of creating the
test object).
Arne
.
- Follow-Ups:
- References:
- Is it good programming to set instance in class without using C-tor
- From: Tony Johansson
- Is it good programming to set instance in class without using C-tor
- Prev by Date: Re: Expressions in C#...
- Next by Date: Re: Remoting to multiple instances of the same application
- Previous by thread: Re: Is it good programming to set instance in class without using C-tor
- Next by thread: Re: Is it good programming to set instance in class without using C-tor
- Index(es):
Relevant Pages
|