473,465 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

when put a class in another class

Hi,

When do you put a class in another class and when not ? It seems in most
case both work fine, but in some case not. I'm not yet smart enough in dotnet
to know when and wy. Can someone enlighten ?

I give example to enlight what I mean. This one has the CFG class in the
class Rx:
namespace TTLocator
{
public partial class Rx: Form
{
public class CFG
{
}
}
}

This one has the CFG class in the same namespace but outside the Rx class:
namespace TTLocator
{
public partial class Rx: Form
{
}

public class CFG
{
}
}

--
rgds, Wilfried
http://www.mestdagh.biz
Nov 17 '05 #1
3 1489
Hi,

Is a design decision, it depends what do you want to achieve, you have to
ask yourself the question:

"Does CFG belong to Rx?

Example 1:

public class Employee : Person
{
public class EmployeeType
}

This example also gives you the oportunity to protect classes, let's suppose
that "EmployeeType" is also for "Employee" use, you just change the modifier
to "private"

Example 2:

public class Employee : Person
{
}

publc class Department
{
}

In this case department is not related at all with the Employee structure.

Hope this helps
Salvador

"Wilfried Mestdagh" wrote:
Hi,

When do you put a class in another class and when not ? It seems in most
case both work fine, but in some case not. I'm not yet smart enough in dotnet
to know when and wy. Can someone enlighten ?

I give example to enlight what I mean. This one has the CFG class in the
class Rx:
namespace TTLocator
{
public partial class Rx: Form
{
public class CFG
{
}
}
}

This one has the CFG class in the same namespace but outside the Rx class:
namespace TTLocator
{
public partial class Rx: Form
{
}

public class CFG
{
}
}

--
rgds, Wilfried
http://www.mestdagh.biz

Nov 17 '05 #2
JAL
In general prefer containment over inheritance. Then realize there are
two types of containment, by reference and by ownership.

http://www.geocities.com/jeff_louie/OOP/oop7.htm
http://www.geocities.com/jeff_louie/OOP/oop12.htm

Regards,
Jeff

Nov 17 '05 #3
When one object is fully dependent of another you would use the ownership
(ie. nested class). If the subordinate object can be used outside the
context of the parent then you would use it by reference.

For instance, a "Wheel" class may have a nested "Spoke" class because the
spoke is useless without the wheel. The "Wallet" class would refer to a
"Money" class because there are LOTS of uses for money!

Inheritance is a different beast altogether which should be used to express
IS-A vice HAS-A relationships. For instance, the "Euro" and "Dollar"
classes would inherit from "Money" and subsequently be refered to by the
"Wallet" class.
bob

"JAL" <Je********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
In general prefer containment over inheritance. Then realize there are
two types of containment, by reference and by ownership.

http://www.geocities.com/jeff_louie/OOP/oop7.htm
http://www.geocities.com/jeff_louie/OOP/oop12.htm

Regards,
Jeff

Nov 17 '05 #4

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

Similar topics

1
by: Kenneth Baltrinic | last post by:
I have a custom collection class that raises OnAdd and OnRemove events. It is used by another class (Class A) as a container for the class's children. Thus in class A's constructor, I instantiate...
3
by: Jacob Gladish | last post by:
In the following code snippet, I am calling into an unmanaged static .lib file from a managed class. I belive that I have to pin the pointer before making the call into the unmanaged code, but I...
3
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user...
20
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable,...
3
by: MIGUEL | last post by:
Hi all, I'm quite lost with how adding web references to a project creates proxy classes. I've developed a web service with two classes inside and that contains three references to three...
2
by: tony | last post by:
Hello! I'm trying to build a class library which has a class called AvestaPlantFunc. In this project building a class libray exist a class called AvestaPlantFunc. In this class is there a...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
4
by: abir | last post by:
I am matching a template, and specializing based of a template, rather than a single class. The codes are like, template<template<typename T,typename Alloc = std::allocator<T> class pix{ }; ...
4
omerbutt
by: omerbutt | last post by:
hi tere i have a page in which i have the requirement that the client has 2 select (Length,Weight)and 1 text(Quantity) inputs and 2 buttons (add and remove) the idea is that the client should enter...
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
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
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...
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...
1
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.