Click here to Skip to main content
15,904,828 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: The programming language you all been waiting for. Pin
Amarnath S22-Jan-16 5:02
professionalAmarnath S22-Jan-16 5:02 
GeneralRe: The programming language you all been waiting for. Pin
Eddy Vluggen22-Jan-16 6:43
professionalEddy Vluggen22-Jan-16 6:43 
GeneralWhy .Net Sucks today Pin
#realJSOP22-Jan-16 3:07
professional#realJSOP22-Jan-16 3:07 
GeneralRe: Why .Net Sucks today PinPopular
Marc Clifton22-Jan-16 3:14
mvaMarc Clifton22-Jan-16 3:14 
GeneralRe: Why .Net Sucks today Pin
Duncan Edwards Jones22-Jan-16 3:16
professionalDuncan Edwards Jones22-Jan-16 3:16 
GeneralRe: Why .Net Sucks today Pin
#realJSOP22-Jan-16 3:18
professional#realJSOP22-Jan-16 3:18 
GeneralRe: Why .Net Sucks today Pin
Duncan Edwards Jones22-Jan-16 3:30
professionalDuncan Edwards Jones22-Jan-16 3:30 
GeneralRe: Why .Net Sucks today Pin
Marc Clifton22-Jan-16 4:18
mvaMarc Clifton22-Jan-16 4:18 
Duncan Edwards Jones wrote:
When do you need it?


The use case that I've come up against in the past is the ability to extend a UI control's behavior to include some common behaviors. For example, what I want is:

class MySmartLabel : Label, CommonToAllControls {}

The idea being here that I can implement behaviors in CommonToAllControls and access them through the derived instance, and the instance can access methods in CommonToAllControls.

If I write it as an interface:

public class MyLabel : Label, ICommonToAllControls {}

I have to implement the interface functions in each class. At best, this means having stubby functions like void DoSomething() {commonality.DoSomething();} and, as you point out, use IoC to pass in an instance of ICommonToAllControls.

Or, I can invert it:
class CommonToAllControls
{
  Control target;
  // ... common stuff I want to do ...
}

But then I lose the ability to reference, without casting, the specific properties/methods of a control when I need them.

There are now other ways to skin the cat -- extension methods, for example.

Now, arguably, one might say that multiple inheritance is bad design because it fixes the implementation, whereas I might want to vary the implementation of CommonToAllControls. I can to a large extend agree with that, it's just that interfaces are a sort of klunky half-way solution to that problem.

Then again, maybe I've got some big gaping hole in my understanding of OOP!

Marc

GeneralRe: Why .Net Sucks today Pin
Philippe Mori22-Jan-16 7:13
Philippe Mori22-Jan-16 7:13 
GeneralRe: Why .Net Sucks today Pin
#realJSOP22-Jan-16 3:20
professional#realJSOP22-Jan-16 3:20 
GeneralRe: Why .Net Sucks today Pin
Jeremy Falcon22-Jan-16 5:55
professionalJeremy Falcon22-Jan-16 5:55 
GeneralRe: Why .Net Sucks today PinPopular
Sascha Lefèvre22-Jan-16 3:32
professionalSascha Lefèvre22-Jan-16 3:32 
GeneralRe: Why .Net Sucks today Pin
U. G. Leander22-Jan-16 3:39
professionalU. G. Leander22-Jan-16 3:39 
GeneralRe: Why .Net Sucks today Pin
#realJSOP22-Jan-16 3:53
professional#realJSOP22-Jan-16 3:53 
GeneralRe: Why .Net Sucks today Pin
User 1013254622-Jan-16 3:34
User 1013254622-Jan-16 3:34 
GeneralRe: Why .Net Sucks today Pin
U. G. Leander22-Jan-16 3:37
professionalU. G. Leander22-Jan-16 3:37 
GeneralRe: Why .Net Sucks today Pin
Sander Rossel22-Jan-16 4:23
professionalSander Rossel22-Jan-16 4:23 
GeneralRe: Why .Net Sucks today Pin
Slacker00722-Jan-16 4:43
professionalSlacker00722-Jan-16 4:43 
GeneralRe: Why .Net Sucks today Pin
#realJSOP22-Jan-16 5:27
professional#realJSOP22-Jan-16 5:27 
GeneralRe: Why .Net Sucks today Pin
Philippe Mori22-Jan-16 6:59
Philippe Mori22-Jan-16 6:59 
GeneralRe: Why .Net Sucks today Pin
snorkie22-Jan-16 9:06
professionalsnorkie22-Jan-16 9:06 
GeneralRe: Why .Net Sucks today Pin
PIEBALDconsult22-Jan-16 9:09
mvePIEBALDconsult22-Jan-16 9:09 
GeneralRe: Why .Net Sucks today Pin
Camilo Reyes22-Jan-16 12:48
professionalCamilo Reyes22-Jan-16 12:48 
GeneralPartially true... PinPopular
Dave Kreskowiak22-Jan-16 2:17
mveDave Kreskowiak22-Jan-16 2:17 
GeneralRe: Partially true... Pin
glennPattonWork322-Jan-16 3:29
professionalglennPattonWork322-Jan-16 3:29 

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.