![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | c# question i have 5 non-static classes Class A, B, C, D, and E Class A creates an instance of class B. what would be a way for classes C D E to pass data into that instance of class B. Class A { B b = new B(); } Tem |
My System Specs![]() |
| | #2 (permalink) |
| | Re: c# question Ten wrote: Quote: > Class A creates an instance of class B. what would be a way for classes > C D E to pass data into that instance of class B. on B directly - if it's OK to have direct access to the object in your model - or you could add methods to A which manipulate B on behalf of C, D and E (which is pretty much a façade pattern). I'd personally go for the façade. Quote: > Tem Chris |
My System Specs![]() |
| | #3 (permalink) |
| | Re: c# question Hi Tem, Since "b" is private inside "A" there's no way for outsiders to send messages (method calls, property setters, ...) to "b". You can, of course, use delegation from "A" to "B"; "a" receives a message and sends a "similar" message to it's private instance of "b". Other things are possible in certain scenario's; for instance when you only need to pass certain data to "b" upon construction or intialization. Is that the case? Kind regards, Marc Vangrieken http://vangrieken.wordpress.com On 6 apr, 21:06, "Ten" <tem1...@xxxxxx> wrote: Quote: > i have 5 non-static classes > Class A, B, C, D, and E > > Class A creates an instance of class B. what would be a way for classes C D > E to pass data into that instance of class B. > > Class A > { > B b = new B(); > > } > > Tem |
My System Specs![]() |
| | #4 (permalink) |
| | Re: c# question On 6 apr, 21:48, Chris Crowther <hik...@xxxxxx> wrote: Quote: > Ten wrote: Quote: > > Class A creates an instance of class B. what would be a way for classes > > C D E to pass data into that instance of class B. > You could either make B available via a property on A and call methods > on B directly - if it's OK to have direct access to the object in your > model - or you could add methods to A which manipulate B on behalf of C, > D and E (which is pretty much a façade pattern). > > I'd personally go for the façade. > Quote: > > Tem > -- > Chris > > hikari.vcf > 1KDownloaden Personally, I wouldn't call it a "Façade" nor "Proxy" (having this little information). "Façade", "Proxy" and "Adapter" are all applications of "Wrapper" with a different intent. None of these intents are hinted in the problem statement. The commonality between the proposed solution, "Façade" and "Proxy" is the usage of "delegation". Of course, as a mental model "Façade" is fine... Kind regards, Marc Vangrieken http://vangrieken.wordpress.com |
My System Specs![]() |
| | #5 (permalink) |
| | Re: c# question i need to pass data to b not just on initialization. do you know where i can find an exmaple of the first method you mentioned? delegation Thanks Tem "Marc Vangrieken" <marc.vangrieken@xxxxxx> wrote in message news:96f39104-1794-40b3-b7c0-06baaacee0ce@xxxxxx Quote: > Hi Tem, > > Since "b" is private inside "A" there's no way for outsiders to send > messages (method calls, property setters, ...) to "b". You can, of > course, use delegation from "A" to "B"; "a" receives a message and > sends a "similar" message to it's private instance of "b". > > Other things are possible in certain scenario's; for instance when you > only need to pass certain data to "b" upon construction or > intialization. Is that the case? > > Kind regards, > Marc Vangrieken > http://vangrieken.wordpress.com > > On 6 apr, 21:06, "Ten" <tem1...@xxxxxx> wrote: Quote: >> i have 5 non-static classes >> Class A, B, C, D, and E >> >> Class A creates an instance of class B. what would be a way for classes C >> D >> E to pass data into that instance of class B. >> >> Class A >> { >> B b = new B(); >> >> } >> >> Tem |
My System Specs![]() |
| | #6 (permalink) |
| | Re: c# question On Sun, 6 Apr 2008 12:06:32 -0700, "Ten" <tem1232@xxxxxx> wrote: Quote: >i have 5 non-static classes >Class A, B, C, D, and E > >Class A creates an instance of class B. what would be a way for classes C D >E to pass data into that instance of class B. > >Class A >{ >B b = new B(); >} > >Tem 1. Make a public readonly property of A that returns b. Then the callers would say: a.B.SomePropertyOfB = 5 Users of A can access any methods/properties of B. 2. Create properties/methods of A that then call the appropriate properties and methods of B. In this case the properties/methods of A may or may not be exactly the same as those of B. You would probably only use this technique if you wanted to expose only a small subset of B's interface to the users of A. You are hiding the existence of a B, and in the future would be free to use a class other than B without the callers having to change their code as long as it offered the same functionality that you expose. |
My System Specs![]() |
| | #7 (permalink) |
| | RE: c# question The gist of the thread - simplest approach - might be: Class A { public B b; A( B b) { this.b = b; } } You pass an instance of B into the ctor for A. Now "B" is a public field of A. The code is ugly, but I hope you get the idea. -- Peter Site: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com Short Urls & more: http://ittyurl.net "Ten" wrote: Quote: > i have 5 non-static classes > Class A, B, C, D, and E > > Class A creates an instance of class B. what would be a way for classes C D > E to pass data into that instance of class B. > > Class A > { > B b = new B(); > } > > Tem > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: c# question On 6 apr, 22:28, "Tem" <tem1...@xxxxxx> wrote: Quote: > i need to pass data to b not just on initialization. > > do you know where i can find an exmaple of the first method you mentioned? > delegation > > Thanks > Tem > > "Marc Vangrieken" <marc.vangrie...@xxxxxx> wrote in message > > news:96f39104-1794-40b3-b7c0-06baaacee0ce@xxxxxx > Quote: > > Hi Tem, Quote: > > Since "b" is private inside "A" there's no way for outsiders to send > > messages (method calls, property setters, ...) to "b". You can, of > > course, use delegation from "A" to "B"; "a" receives a message and > > sends a "similar" message to it's private instance of "b". Quote: > > Other things are possible in certain scenario's; for instance when you > > only need to pass certain data to "b" upon construction or > > intialization. Is that the case? Quote: Quote: > > On 6 apr, 21:06, "Ten" <tem1...@xxxxxx> wrote: Quote: > >> i have 5 non-static classes > >> Class A, B, C, D, and E Quote: Quote: > >> Class A creates an instance of class B. what would be a way for classes C > >> D > >> E to pass data into that instance of class B. Quote: Quote: > >> Class A > >> { > >> B b = new B(); Quote: Quote: > >> } Quote: Quote: > >> Tem http://en.wikipedia.org/wiki/Delegation_(programming). Also usefull: Explanation of composition and aggregation: http://en.wikipedia.org/wiki/Aggrega...29#Aggregation. The examples are in C++, but with a little imagination it can be C#. Kind regards, Marc Vangrieken http://vangrieken.wordpress.com |
My System Specs![]() |
| | #9 (permalink) |
| | Re: c# question >I think it's perfectly reasonable to describe briefly Quote: > solutions appropriate to different problem statements, given that the OP > has provided so little to work with. context. But, anyway, that's not what this post is about... Kind regards, Marc Vangrieken http://vangrieken.wordpress.com |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| IE8 Question | Vista General | |||
| escape character question - hopefully an easy question | PowerShell | |||
| vista genral question and ultimate question | Vista General | |||
| Dual boot system question and family deal discount question | Vista General | |||
| RC1 Cd Key Question | Vista installation & setup | |||