Click here to Skip to main content
15,913,941 members
Home / Discussions / C#
   

C#

 
AnswerRe: How set the background of an MDI container window? Pin
phil.o29-Oct-11 23:15
professionalphil.o29-Oct-11 23:15 
GeneralRe: How set the background of an MDI container window? Pin
Dave Kreskowiak30-Oct-11 3:23
mveDave Kreskowiak30-Oct-11 3:23 
AnswerRe: How set the background of an MDI container window? Pin
Ravi Bhavnani30-Oct-11 12:06
professionalRavi Bhavnani30-Oct-11 12:06 
QuestionMdi Form Pin
jojoba2029-Oct-11 1:14
jojoba2029-Oct-11 1:14 
AnswerRe: Mdi Form Pin
tgurlevik29-Oct-11 2:43
tgurlevik29-Oct-11 2:43 
AnswerRe: Mdi Form Pin
Dave Kreskowiak29-Oct-11 3:15
mveDave Kreskowiak29-Oct-11 3:15 
QuestionCasting to Abstract 'parent' rather than casting to Interface ? Pin
BillWoodruff28-Oct-11 22:31
professionalBillWoodruff28-Oct-11 22:31 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? PinPopular
Luc Pattyn29-Oct-11 1:37
sitebuilderLuc Pattyn29-Oct-11 1:37 
Hi Bill,

this is how I see the matter:

1.
when you decide to use a factory, it tells me you want to be able to get an instance of a number of possible types, where the exact type will depend on some parameters; and you also have good reasons to put the creation of those different instances in a common method because, to you, they share some common behavior, and its that behavior you're interested in.

Example: you could want a factory that returns either a Monkey or a Lion; you would not want a factory that either creates a Monkey or a ProgrammingLanguage.

2.
The common behavior is the only thing that matters to you; if you want Animal behavior, the Monkey-and-Lion example would be good, and both Monkey and Lion could inherit from Animal. Whether the inheritance is direct or distant (e.g. through Mammal or Quadruped or QuadrupedMammal) is irrelevant; the base class possibly being abstract doesn't matter either.

3.
As always in inheritance, a number of languages (all .NET, Java, ...) don't support multiple inheritance, however they offer a cheap almost-replacement (arguable) and that is an interface. So in a factory, if all the Monkeys and Lions ever do for you is walk, then it would be cheaper (i.e. less restrictive, and not consuming the single inheritance) to have Monkeys and Lions implement IWalk, so whatever the factory returns, you can make it Walk(). Much simpler than having the code that calls the factory worry about the exact genealogy of your Animals, Mammals, Quadrupeds, and what have you.

Conclusion: IMO factories should return an interface, unless you're pretty sure about the (stability of the) class hierarchy. It is in fact a weaker form of the "separation of concerns" principle.

Smile | :)

PS: you're right, way too interesting to be handled in Q&A Laugh | :laugh:
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Not Active29-Oct-11 5:17
mentorNot Active29-Oct-11 5:17 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Luc Pattyn29-Oct-11 5:45
sitebuilderLuc Pattyn29-Oct-11 5:45 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
BillWoodruff29-Oct-11 16:26
professionalBillWoodruff29-Oct-11 16:26 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Luc Pattyn29-Oct-11 17:40
sitebuilderLuc Pattyn29-Oct-11 17:40 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
PIEBALDconsult29-Oct-11 4:27
mvePIEBALDconsult29-Oct-11 4:27 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
BillWoodruff29-Oct-11 16:30
professionalBillWoodruff29-Oct-11 16:30 
GeneralRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
PIEBALDconsult29-Oct-11 17:28
mvePIEBALDconsult29-Oct-11 17:28 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
Abhinav S29-Oct-11 17:46
Abhinav S29-Oct-11 17:46 
AnswerRe: Casting to Abstract 'parent' rather than casting to Interface ? Pin
BobJanova30-Oct-11 23:36
BobJanova30-Oct-11 23:36 
QuestionC# linq working with list controls Pin
classy_dog28-Oct-11 14:33
classy_dog28-Oct-11 14:33 
AnswerRe: C# linq working with list controls Pin
BillWoodruff28-Oct-11 14:59
professionalBillWoodruff28-Oct-11 14:59 
GeneralRe: C# linq working with list controls Pin
classy_dog28-Oct-11 17:02
classy_dog28-Oct-11 17:02 
GeneralRe: C# linq working with list controls Pin
BillWoodruff28-Oct-11 18:57
professionalBillWoodruff28-Oct-11 18:57 
QuestionWhat does this code segment mean?? Pin
Goalie3528-Oct-11 11:01
Goalie3528-Oct-11 11:01 
AnswerRe: What does this code segment mean?? PinPopular
harold aptroot28-Oct-11 11:17
harold aptroot28-Oct-11 11:17 
QuestionBitconverter.GetBytes() issue Pin
Blubbo28-Oct-11 8:16
Blubbo28-Oct-11 8:16 
AnswerRe: Bitconverter.GetBytes() issue Pin
Mark Salsbery28-Oct-11 8:36
Mark Salsbery28-Oct-11 8:36 

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.