creating class

  • Thread starter Thread starter TS
  • Start date Start date
T

TS

When have a class, but need some info that is contained in other class, is
it worth the overhead to instantiate both objects if you only need 2
properties, or let those other properties piggyback on the first class which
makes it not so OO?

Say you had a Home class & and HomeOwner class. If you had clicked on the
details of the home class, you would want to display all things about the
home, and maybe the homeOwner class' owner name property. So you would have
to load the whole HomeOwner class for a single property.

thanks
 
TS,

I think that it depends on the context. If within your context you have
a HomeOwner loaded already (for some particular operation), I would say use
that. Otherwise, I would create a new one.

Of course, only you can determine what the appropriate context is.
Basically, I would say that if you have one already, use it (in the same
operation, not over different operations), otherwise, create a new one.

Hope this helps.
 
Hi TS,

Yes, I agree with "Nicholas Paldino [.NET/C# MVP]"'s reply. Additionally, I
think your scenario is something like composition structure in OOP. That is
HomeOwner class is part feature of Home class, so it is embeded as a field
in the Home class, then expose out as a property.

Normally, for this situation, we usually create an HomeOwner instance in
the property at the first access, then further operation to the property
should be occured on this first created instance, a little like singlton.

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.
 
"Jeffrey Tan[MSFT]" said:
Normally, for this situation, we usually create an HomeOwner instance in
the property at the first access, then further operation to the property
should be occured on this first created instance, a little like singlton.

Except that the the pattern is called Creator. =)

I am also a fan of lazy loading. This is typically a performance enhancher I
take into account early in design.
Finding suitable spots to lazy load can make applications start way much
faster.

An extreme example: I can think of one application that fails miserably in
this aspect. Have you ever decided not to open a .pdf in Acrobat Reader 6.0
becuase it loads like a zillion plug-ins when it starts. I have. AR 7 solves
this long load-time by actually checking what features the .pdf needs and
loads only theese at startup.

But from my experience you should do an analysis on what actually can be
lazy loaded.

I once wrote several classes that was so very cool in not loading anything
until needed. Well, by the time we integrated all these cool classes
together into sequences I found that the first method called caused a
chain-reaction that loaded just about everything at startup anyways...

My Bad!
- Michael S
 
Hi Ts,

Does our replies 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.
 
Back
Top