Click here to Skip to main content
15,891,372 members
Home / Discussions / C#
   

C#

 
QuestionInheritance Pin
lukeer26-Aug-11 3:47
lukeer26-Aug-11 3:47 
AnswerRe: Inheritance Pin
Rob Philpott26-Aug-11 3:55
Rob Philpott26-Aug-11 3:55 
AnswerRe: Inheritance Pin
MicroVirus26-Aug-11 4:17
MicroVirus26-Aug-11 4:17 
GeneralMessage Removed Pin
26-Aug-11 5:40
mentorNot Active26-Aug-11 5:40 
GeneralRe: Inheritance Pin
MicroVirus26-Aug-11 6:09
MicroVirus26-Aug-11 6:09 
GeneralMessage Removed Pin
26-Aug-11 7:10
mentorNot Active26-Aug-11 7:10 
GeneralRe: Inheritance Pin
jschell26-Aug-11 8:36
jschell26-Aug-11 8:36 
GeneralRe: Inheritance Pin
MicroVirus26-Aug-11 14:05
MicroVirus26-Aug-11 14:05 
Mark Nischalke wrote:
Don't you think this would have been a better response to the OP than "this structure is quite odd and you should adjust your design"? How would they have know what odd meant or how it should be redesigned in your opinion?


You're just sulking because you disagree.

At any rate, maybe it'd be a better response to the OP if I explicitly explained the meaning of every word that is over 6 letters; after all, how are they supposed to know all those difficult words?
Why don't I? This has to do with estimating someone's level of knowledge and adjusting your answer in response. Obviously, I have a higher estimate of the OP's knowledge in this than you do. In the same way that I don't give the definition of every English word that is over 6 letters, I don't give explanation of what the word 'odd' means in this context (it was logical to me). About adjusting the design, well... like you said yourself, it's an example the OP gave, so I can't say anything relevant about that (at least, not that hadn't already been said by others). I'd need to know the actual design, and even then there might be multiple 'good' designs to go from.
Secondly, I refrained from a more elaborate explanation, because I preferred to wait and see if the OP is at all interested, before I waste time writing pages of info no one is ever going to read or care about. I find that people who are interested usually either understand it, or ask for explanation. If they're not interested, then there's no point in typing more than a succinct response in the first place.

Either way, you're very belittling in your response. Rather than appreciating a decent response, you snap out like I offended you personally. I find it hard to understand what warrants such a reaction. Therefore, I might be less than courteous in my response here; you reap what you sow (goes for me too).

To a more insightful point:

Mark Nischalke wrote:
You mean this line?

FirstDerived firstDerived = new FirstDerived();

Well, yes, of course it is different. It is being called in class SecondDerived. I don't see anything odd about that.

Well, for one thing, you missed the line that was odd, in the quote. At any rate, I will attempt to explain. Considering the following example, which is design-wise equivalent to the original:
C#
class Base
{
  protected abstract void DoSomething();
}

class Derived : Base
{
  protected override void DoSomething() {...}
  
  private void SomethingElse()
  {
    CompletelyDifferent otherObject = new CompletelyDifferent();
    otherObject.SomeFunction(); // Error! It's protected
  }
}

class CompletelyDifferent
{
  protected void SomeFunction() {...}
}

Now I hope you agree that the line with the Error is an error for a good reason. And that trying to circumvent this error in any way is odd (or at least, bad practice).

The equivalence between this and the case where the two classes share a common base, from a design point of view, comes from the fact that having a shared element in no way means they have private access to each other. So, in our discussion of design philosophy, we are as well talking about the original example as this one.
Consider, for instance, a base Stream class and then a derived FileStream and an InternetStream. Even though they share a common base (Stream), they are totally unrelated, as FileStream knows nothing of streaming from the internet and InternetStream knows nothing of files. It would be extremely odd if FileStream then could have privileged (protected) access to a method InternetStream, under the nomer 'but they share a common base'. They are completely different and thus should be treated as such.
Sure, the 'hack' might allow it (not entirely sure that it does, but we're saying it does for the discussion), but it is a still a violation of the principles of encapsulation. It's protected for a reason.

Now of course, a fix to the above example would be to make SomeFunction public (or internal) so it can be properly accessed, but whether this is appropriate depends on the actual situation.

Mark Nischalke wrote:
It's not an error. It is someone trying to learn, giving an example and asking for an explaination.

I was, of course, referring to the circumvention of the protected access specifier, which is an error.
GeneralMessage Removed Pin
26-Aug-11 15:00
mentorNot Active26-Aug-11 15:00 
GeneralRe: Inheritance Pin
Anna-Jayne Metcalfe27-Aug-11 0:04
Anna-Jayne Metcalfe27-Aug-11 0:04 
GeneralRe: Inheritance Pin
Hans Dietrich27-Aug-11 6:04
mentorHans Dietrich27-Aug-11 6:04 
GeneralRe: Inheritance Pin
Anna-Jayne Metcalfe27-Aug-11 6:17
Anna-Jayne Metcalfe27-Aug-11 6:17 
GeneralRe: Inheritance Pin
MicroVirus27-Aug-11 8:46
MicroVirus27-Aug-11 8:46 
GeneralRe: Inheritance Pin
MicroVirus27-Aug-11 2:41
MicroVirus27-Aug-11 2:41 
GeneralRe: Inheritance Pin
lukeer27-Aug-11 3:33
lukeer27-Aug-11 3:33 
GeneralRe: Inheritance Pin
lukeer27-Aug-11 3:21
lukeer27-Aug-11 3:21 
GeneralRe: Inheritance Pin
lukeer27-Aug-11 3:19
lukeer27-Aug-11 3:19 
GeneralRe: Inheritance Pin
MicroVirus27-Aug-11 5:40
MicroVirus27-Aug-11 5:40 
AnswerRe: Inheritance [modified] Pin
Shameel26-Aug-11 4:40
professionalShameel26-Aug-11 4:40 
AnswerRe: Inheritance Pin
ClockEndGooner27-Aug-11 19:00
ClockEndGooner27-Aug-11 19:00 
GeneralRe: Inheritance Pin
ClockEndGooner27-Aug-11 19:05
ClockEndGooner27-Aug-11 19:05 
QuestionADD "CorelDraw" file into C# App Pin
Mahtab77726-Aug-11 2:08
Mahtab77726-Aug-11 2:08 
AnswerRe: ADD "CorelDraw" file into C# App Pin
Wayne Gaylard26-Aug-11 2:36
professionalWayne Gaylard26-Aug-11 2:36 
GeneralRe: ADD "CorelDraw" file into C# App Pin
Mahtab77728-Aug-11 2:59
Mahtab77728-Aug-11 2:59 
GeneralRe: ADD "CorelDraw" file into C# App Pin
Mahtab77729-Aug-11 21:01
Mahtab77729-Aug-11 21:01 

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.