473,802 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ 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 1507
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 "EmployeeTy pe" 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********@yah oo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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
2508
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 an instance of the collection class and register event handlers for the two events. For a give instance of Class A, when is the appropriate time to release these handlers prior to the instances destruction? --Ken Baltrinic
3
2924
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 don't completely understand when a pin is required. Any thoughts? void p4dn::ClientUser::OutputError( System::String* errString ) { System::IntPtr ptr = Marshal::StringToHGlobalAnsi( errString ); // does this need to be pinned?
3
1417
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 id, user name, full name, security level, department, etc.). Would I do better to create a class instead? Also, if I did, would I simply store the ID in the session and when accessing the class (User.FullName, User.SecurityLevel, etc.) then check the...
20
7524
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, but this seems to rely on a call from the application, e.g. MyClass.Dispose()
3
5768
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 DLLs. After building it up, I've deployed it on the web server. From my Windows application, I then add a web reference to that web service.
2
1687
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 method called IsBottomMixValid. Code not relevant for the question has been removed. This method IsBottomMixValid has one parameter and the type for this parameter is MeltPracDataGmix meaning passing class reference MeltPracDataGmix.
15
2177
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 (a_obj) of a class type (A), then we need to define A as well, but if B has a pointer to A, then we only need to forward declare A. I was told this is because the compiler needs to see the implemenation of A when allocating memory for a_obj. ...
4
2063
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{ }; template<> class pix<vector>{
4
1591
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 some number in the quantity field and hit the add button and he could add another row with the same fields and then he could again enter the quantity and so on , i have done all this successfully ,in FF when i add row another row appears under it and...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10304
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.