[C#] Override a property.. ARGH!

I agree, I don't think it is either, but it's a healthy discussion, even if it does not provide a conclusion, it may help others come to their own. :)

True – I find discussions like this to be quite helpful for myself, as they make me think more about what I'm arguing for/against :)

How is an arbitrary interface going to stop that? If both elephant and duck implement "public void Quack()" and "IQuackable" how is that so safe against not implementing any thing and being dynamic? :)

Because an interface is more than just a list of members that an implementing type has to expose: it specifies a behavioural contract that these members should adhere to. IQuackable isn't a great example, because a Quack method is fairly limited in what it might mean (and the interface isn't describing how Quack should behave or what its purpose is – a better name might be IDuck or something), but what if Quack means something else in a different context? Indeed, an interface that exists solely to guarantee that a certain method exists is defeating the point in interfaces altogether; the interface should exist to contractualize a particular behaviour, while the members of the interface should simply expose that behaviour.

You don't call the Quack method just because you want to call a method whose name is Quack; you call it because you want it to do something. The behaviour of a method is it what matters, not its name.

Granted, an interface doesn't prevent the implementing type from exposing something that has the wrong behaviour, but it at least says what the behaviour should be so that the onus lies on the client code to implement it correctly. Another advantage of interfaces (in C# at least) is that they allow for multiple implementations of the same method under different interfaces, so if a type has its own Quack method, but wants to implement two other interfaces that specify a method of the same signature but with different meanings, it can do that by using explicit implementation.

That it does, whilst it also sucks for anyone else wanting to override the type on a property/field between types that do not have a parent interface. I'm above certain I'm not the only one. :)

Probably not, but I don't think it's a particularly common problem.

I'm glad you were tempted :) Yes, there is not much support for Seaside - and on a side note there is free hosting for non-commerical site at http://www.seasidehosting.st :)

Cool, I'll try it out!

Now we're getting somewhere with this discussion. :) I'm not a mathematical minded person other than I am a very logical man. If something is going to break, I want it to break, so I can fix and learn. I do not want something to always alert me long in advance. This of course only applies to software, if I were building a house or something that's a different story entirely. As far as software is concerned, there is so much that cannot be detected at compile time (in terms of desired behaviour) then why even bother with such fallacies (in this case at least) as inconsistency - an inconsistency which is *purely* based on two of my objects not implementing an arbitrary label. :)

I understand what you're saying, though I personally find it more useful to see where things will go wrong because I've messed up the typing (and as I've said before it can help find semantic/design problems as well). You are, of course, absolutely right that nominative/static typing can only catch a small amount of what could go wrong at runtime, though.

Also, for what it's worth, what you're talking about there is nominative typing, which isn't a requirement for static a typing system. A good example of a language that is statically typed but uses type inference rather than nominative typing is Haskell (which I also love :cool:).

By the way, C# is getting some elements of dynamic typing in version 4.0 :p
http://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Dynamic_member_lookup
 
Last edited:
The intention of an interface is to contractually oblige a (or more than one) behaviour; but in reality it's not that - it's literally just a spec of what methods and/or properties must be available; I could put any behaviour I like behind it and still satisfy the interface. Bad practice, of course, but I think it's a bit zealous to call them contracts (by anyone and everyone, not just you!) :)

I'm certain others have this problem. It is simply a problem because we are using two separate WSDL services for the same (overall) system, one that is an extension of the behaviour of the other, but (of course) can only reference them via the "Service Reference" names and as such, different namespaces. The classes even have the same name, and the same interface - merely a different namespace.
 
Last edited:
You removed the code samples – was going to have a look at those but never mind :p

Couldn't quite figure out why you wanted a new property with exactly the same type and name though.
 
Different namespaces :) Which are via the different service references. One is available to the parent, the other to the child. I.e. The crux of the problem (other than inability to override a fields type by extension :p)
 
Last edited:
OMFG !

I read the code up the top and a little of this thread and can't believe it !

Seriously OP - Heed some advice ... GO AND LEARN SOME basics of OOP/OOD maybe some design patterns too ?
 
Heed some advice yourself, I am a fully fledged OO Developer in a fulltime Development role. I am the lead developer and contributor for SSpec - a Behaviour Driven Design framework, sister project of RSpec, and an actual pioneering project in the Development world as far as Testing goes. I have been developing for nearly 9 years, and make a tidy sum from it.

I am questioning one of the very aspects of C#'s behviour-by-design aspects. Of which, after seeing from links found on Google and posted by others in this thread, has been addressed by the authors of C#. In other words, they agree with me.

So, here's some more advice just for you: leave this thread.

Yes, I've just been watching Scrubs and wish I was just like Dr. Cox
 
P.S. Inquisitor - I removed the code samples because they were not representative of the issue. :) I've re-read my OP and amended below to be more true to the real code (unfortunately I cannot post directly, as it is under NDA from Royal Mail :p):

ClassA.cs:
Code:
using ServiceReferenceOne.TypeA;

namespace NamespaceA
{
  public class ClassA
  {
    public TypeA property = new TypeA();

    public void SetSomething(string foo)
    {
      property.blah = foo;
    }
  }
}

ClassB.cs
Code:
using ServiceReferenceTwo.TypeA;
using NamespaceA;

namespace NamespaceB
{
  public class ClassB : ClassA
  {
    new public TypeA property = new TypeA();
  }
}
Elsewhere:
Code:
using NamespaceB;
using ServiceReferenceTwo;

public class Foo
{
  public static void Main(string[] args)
  {
    ClassB foo = new ClassB();
    foo.SetSomething("woowoo");
    if (foo.property.blah == null)
    {
      /*
       * yes, it's null. :( but on inspection during debug,
       * "woowoo" *is* stored, but on base.property - not on the 'new' property.
       */
    }
  }
}
I've fully qualified the TypeA usings merely to highlight they are from different service references. Take note that SetSomething only interacts with base.property, not on the 'new' property.

Also; PsychoDuck - I just spotted the syntax error you mentioned :)
 
Last edited:
Heed some advice yourself, I am a fully fledged OO Developer in a fulltime Development role. I am the lead developer and contributor for SSpec - a Behaviour Driven Design framework, sister project of RSpec, and an actual pioneering project in the Development world as far as Testing goes. I have been developing for nearly 9 years, and make a tidy sum from it.

I am questioning one of the very aspects of C#'s behviour-by-design aspects. Of which, after seeing from links found on Google and posted by others in this thread, has been addressed by the authors of C#. In other words, they agree with me.

So, here's some more advice just for you: leave this thread.

Yes, I've just been watching Scrubs and wish I was just like Dr. Cox

Woah have you got any medals too ?

I'm LMAO as this BS needs to be open for discussion elsewhere not here.

AND yes I do re-iterate the need for you to learn how to code.
 
Aura - How about you learn to write a coherent post before you try trolling someone? Jesus Christ..

Fair play though, DJ is usually quite arrogant, but his ramblings about x-amount of years, lead developer of that, blah blah blah was 'especially' arrogant and pretty funny.

Aura, you should know DJ by now.
DJ, hmmmm, turning the spotlight on yourself and coming out with the first paragraph wasn't 'really' necessary was it.

:)
 
There was a hidden message, visible in the quote :) I had literally that second just stopped watching Scrubs with an excellent rant from Dr. Cox. :)

I was inspired. He is my idol. If it were biologically possible, I'd have his babies.
 
Back
Top Bottom