Click here to Skip to main content
15,911,646 members
Home / Discussions / C#
   

C#

 
Questionpassing data from child form to parent Pin
tasumisra12-Dec-09 18:10
tasumisra12-Dec-09 18:10 
AnswerRe: passing data from child form to parent Pin
dan!sh 12-Dec-09 18:56
professional dan!sh 12-Dec-09 18:56 
GeneralRe: passing data from child form to parent Pin
tasumisra12-Dec-09 19:38
tasumisra12-Dec-09 19:38 
GeneralRe: passing data from child form to parent Pin
dan!sh 12-Dec-09 21:15
professional dan!sh 12-Dec-09 21:15 
GeneralRe: passing data from child form to parent Pin
OriginalGriff12-Dec-09 22:20
mveOriginalGriff12-Dec-09 22:20 
GeneralRe: passing data from child form to parent Pin
dan!sh 13-Dec-09 0:05
professional dan!sh 13-Dec-09 0:05 
GeneralRe: passing data from child form to parent Pin
tasumisra13-Dec-09 2:47
tasumisra13-Dec-09 2:47 
GeneralRe: passing data from child form to parent Pin
OriginalGriff13-Dec-09 2:52
mveOriginalGriff13-Dec-09 2:52 
d@nish wrote:
May I ask why?


OOP is based around a small number of key concepts - how many depends on who you talk to - but most agree that important ones are Encapsulation, Modularity, and Abstraction.

Public properties do provide these, yes, but only in one direction - from the outside world to the class containing the property definitions.
So, if Form1 consumes the info and Form2 generates it as in the earlier posts, handling it with public properties needs:
Form2:

form1instance.property = value;

Form1:

property set method - Handle value.

What happens if you have two copies of Form1, both of which need to consume the data?

Form2:

form1instance1.property = value;
form1instance2.property = value;

Form1:

property set method - handle value.

Yes - you have to change the data provider to cope with the new instance of the data consumer. The same thing happens if you want to reuse the data provider for some other purpose which does not need a data consumer. Either you have to change the provider to cope with the lack of a consumer, or you have to provide a consumer which does nothing to cope with the provider.

If instead you throw an event "I have data to be consumed" and subscribe to that event as needed in your consumers, you can have as many consumers of the data as you like without changing consumer or provider. This includes zero consumers, that's why the "if (ca != null)" in my original post was there.

There is nothing wrong with using public properties - I do on a regular basis - but when the event handling mechanism is both there and simple to use, it is worth getting used to as early as possible.

Does that make sense? (It was typed quickly and may be a little impenetrable)

All those who believe in psycho kinesis, raise my hand.

GeneralRe: passing data from child form to parent Pin
DaveyM6913-Dec-09 4:10
professionalDaveyM6913-Dec-09 4:10 
GeneralRe: passing data from child form to parent Pin
dan!sh 13-Dec-09 5:38
professional dan!sh 13-Dec-09 5:38 
GeneralRe: passing data from child form to parent Pin
tasumisra13-Dec-09 2:45
tasumisra13-Dec-09 2:45 
QuestionHttpWebRequest.BegineGetResponse() not running asynchronously… Pin
royk12312-Dec-09 17:53
royk12312-Dec-09 17:53 
AnswerRe: HttpWebRequest.BegineGetResponse() not running asynchronously… Pin
Luc Pattyn13-Dec-09 2:04
sitebuilderLuc Pattyn13-Dec-09 2:04 
GeneralRe: HttpWebRequest.BegineGetResponse() not running asynchronously… Pin
royk12314-Dec-09 0:37
royk12314-Dec-09 0:37 
Questionconnectionstring Pin
farokhian12-Dec-09 10:03
farokhian12-Dec-09 10:03 
QuestionException Handling Pin
Razanust12-Dec-09 7:53
Razanust12-Dec-09 7:53 
AnswerRe: Exception Handling Pin
PIEBALDconsult12-Dec-09 8:52
mvePIEBALDconsult12-Dec-09 8:52 
QuestionSchedulle a task for some days of the week Pin
baranils12-Dec-09 6:14
baranils12-Dec-09 6:14 
AnswerRe: Schedulle a task for some days of the week Pin
Abhinav S12-Dec-09 6:20
Abhinav S12-Dec-09 6:20 
AnswerRe: Schedulle a task for some days of the week Pin
Luc Pattyn12-Dec-09 6:22
sitebuilderLuc Pattyn12-Dec-09 6:22 
GeneralRe: Schedulle a task for some days of the week Pin
baranils12-Dec-09 6:35
baranils12-Dec-09 6:35 
GeneralRe: Schedulle a task for some days of the week Pin
baranils12-Dec-09 6:56
baranils12-Dec-09 6:56 
GeneralRe: Schedulle a task for some days of the week Pin
Luc Pattyn12-Dec-09 7:21
sitebuilderLuc Pattyn12-Dec-09 7:21 
GeneralRe: Schedulle a task for some days of the week Pin
baranils12-Dec-09 7:38
baranils12-Dec-09 7:38 
GeneralRe: Schedulle a task for some days of the week Pin
PIEBALDconsult12-Dec-09 8:55
mvePIEBALDconsult12-Dec-09 8:55 

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.