Click here to Skip to main content
15,921,203 members
Home / Discussions / C#
   

C#

 
Questioncystal report Pin
cse.vidhya25-Jun-08 0:57
cse.vidhya25-Jun-08 0:57 
AnswerRe: cystal report Pin
Christian Graus25-Jun-08 1:36
protectorChristian Graus25-Jun-08 1:36 
AnswerRe: cystal report Pin
leppie25-Jun-08 2:03
leppie25-Jun-08 2:03 
AnswerRe: cystal report Pin
Verghese25-Jun-08 3:21
Verghese25-Jun-08 3:21 
Questioncrystal report - very urgent Pin
cse.vidhya25-Jun-08 0:53
cse.vidhya25-Jun-08 0:53 
QuestionMustUnderstand WCF connecting to Java web service [modified] Pin
Simon Lime25-Jun-08 0:52
Simon Lime25-Jun-08 0:52 
NewsRe: MustUnderstand WCF connecting to Java web service Pin
Simon Lime7-Jul-08 1:06
Simon Lime7-Jul-08 1:06 
QuestionOOP question: correct obect composition in C# Pin
Metal7625-Jun-08 0:41
Metal7625-Jun-08 0:41 
Hi, I have a question on correct usage of object composition. This is the situation I'm facing:

class Address
{    
    // An address is composed of several fields
    private byte _FieldA;
    private byte _FieldB;
    private byte _FieldC;

    // Each field is exposed with a public property
    public byte FieldA
    {
        set { _FieldA = value; }
        get { return _FieldA; }
    }
    // ... and so on for the other fields

    // I have several useful public methods for address manipulation
    public void SetAddress (byte fieldA, byte fieldB, byte fieldC);
    public void DoStuff(...)
    public void DoOtherStuff(...)
    ...
}


class Message
{    
    // A message contains 2 addresses
    public Address SourceAddress = new Address();
    public Address DestAddress = new Address();
}


A client which instantiates a message should only be able to access the address fields and to invoke SetAddress().

By declaring SourceAddress and DestAddress objects as public, I can write things like message.SourceAddress.FieldA, message.DestAddress.SetAddress(), with no need for additional code. However, I also expose other methods like DoStuff() etc, which a message should not be able to call.

On the other hand, if I declare SourceAddress and DestAddress as private, I can control what I expose to the client but I'm also forced to add a lot of code: public properties and methods like SourceAddressFieldA, SourceAddressFieldB, SetSourceAddress(), all duplicated for DestAddress... this means a lot of code duplication, and less flexibility (imagine if I have to add other Address fields to Message...).

Is there a "sweet spot"? Is there a correct (or better, preferred) way to expose the behaviour of child objects in C#?

Regards,
Andrea
AnswerRe: OOP question: correct obect composition in C# Pin
Christian Graus25-Jun-08 0:49
protectorChristian Graus25-Jun-08 0:49 
Questionhow i can run a dll Pin
wasimsharp25-Jun-08 0:22
wasimsharp25-Jun-08 0:22 
AnswerRe: how i can run a dll Pin
Christian Graus25-Jun-08 0:23
protectorChristian Graus25-Jun-08 0:23 
GeneralRe: how i can run a dll Pin
wasimsharp25-Jun-08 0:37
wasimsharp25-Jun-08 0:37 
GeneralRe: how i can run a dll Pin
Christian Graus25-Jun-08 0:45
protectorChristian Graus25-Jun-08 0:45 
AnswerRe: how i can run a dll Pin
Mbah Dhaim25-Jun-08 3:43
Mbah Dhaim25-Jun-08 3:43 
Questiontreeview and mdichild Pin
ginji2025-Jun-08 0:06
ginji2025-Jun-08 0:06 
AnswerRe: treeview and mdichild Pin
DaveyM6925-Jun-08 7:56
professionalDaveyM6925-Jun-08 7:56 
GeneralRe: treeview and mdichild [modified] Pin
ginji2025-Jun-08 15:15
ginji2025-Jun-08 15:15 
QuestionInterfaces and Casting - I'm struggling. Pin
stovesy24-Jun-08 23:57
stovesy24-Jun-08 23:57 
AnswerRe: Interfaces and Casting - I'm struggling. Pin
leppie25-Jun-08 2:11
leppie25-Jun-08 2:11 
GeneralRe: Interfaces and Casting - I'm struggling. Pin
stovesy25-Jun-08 2:27
stovesy25-Jun-08 2:27 
GeneralRe: Interfaces and Casting - I'm struggling. Pin
leppie25-Jun-08 4:51
leppie25-Jun-08 4:51 
GeneralRe: Interfaces and Casting - I'm struggling. Pin
stovesy25-Jun-08 5:33
stovesy25-Jun-08 5:33 
AnswerRe: Interfaces and Casting - I'm struggling. Pin
leppie25-Jun-08 4:54
leppie25-Jun-08 4:54 
GeneralRe: Interfaces and Casting - I'm struggling. Pin
stovesy25-Jun-08 5:36
stovesy25-Jun-08 5:36 
GeneralRe: Interfaces and Casting - I'm struggling. Pin
leppie25-Jun-08 5:43
leppie25-Jun-08 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.