digitalmars.D - Does alias prevent hijacking?
- Kagamin (17/17) May 29 2011 class Base
- Jacob Carlborg (4/21) May 30 2011 Yes, but you've made an active choice by adding the alias.
- Matthew Ong (9/33) Jun 02 2011 alias assumes both the Base Class and Derived Class are coded by the
- Steven Schveighoffer (11/43) Jun 03 2011 You can't get this reported. But first, this case is not so common, and...
- Matthew Ong (16/19) Jun 04 2011 I was *not* referring to my earlier suggestions about new pair of
class Base { void foo(string s){} } class Derived: Base { alias Base.foo foo; void foo(long s){} } So far so good. Now add new method to the Base class. class Base { void foo(string s){} void foo(int s){} } Now behavior of the calling code silently changes.
May 29 2011
On 2011-05-30 08:53, Kagamin wrote:class Base { void foo(string s){} } class Derived: Base { alias Base.foo foo; void foo(long s){} } So far so good. Now add new method to the Base class. class Base { void foo(string s){} void foo(int s){} } Now behavior of the calling code silently changes.Yes, but you've made an active choice by adding the alias. -- /Jacob Carlborg
May 30 2011
On 5/30/2011 7:50 PM, Jacob Carlborg wrote:On 2011-05-30 08:53, Kagamin wrote:alias assumes both the Base Class and Derived Class are coded by the *same* person and within the *same* module. What *if* that is *not* the case, I think Kagamin is trying to show that *How* would the coder of the Derived be *notify* of this change *even* when alias is used. -- Matthew Ong email: ongbp yahoo.comclass Base { void foo(string s){} } class Derived: Base { alias Base.foo foo; void foo(long s){} } So far so good. Now add new method to the Base class. class Base { void foo(string s){} void foo(int s){} } Now behavior of the calling code silently changes.Yes, but you've made an active choice by adding the alias.
Jun 02 2011
On Fri, 03 Jun 2011 02:46:23 -0400, Matthew Ong <ongbp yahoo.com> wrote:On 5/30/2011 7:50 PM, Jacob Carlborg wrote:You can't get this reported. But first, this case is not so common, and second, an *added* overload to a base class is likely to be similar in nature to the other overloads. A *new* overload set added to the base class is unlikely to be related to some similarly named derived class method. There is not an easy solution to this, having both foo(int) and foo(long) can cause trouble in the same overload set. I agree it is a possible case for hijacking, but I don't think it's common enough to require more syntax. -SteveOn 2011-05-30 08:53, Kagamin wrote:alias assumes both the Base Class and Derived Class are coded by the *same* person and within the *same* module. What *if* that is *not* the case, I think Kagamin is trying to show that *How* would the coder of the Derived be *notify* of this change *even* when alias is used.class Base { void foo(string s){} } class Derived: Base { alias Base.foo foo; void foo(long s){} } So far so good. Now add new method to the Base class. class Base { void foo(string s){} void foo(int s){} } Now behavior of the calling code silently changes.Yes, but you've made an active choice by adding the alias.
Jun 03 2011
On 6/3/2011 9:23 PM, Steven Schveighoffer wrote:*How* would the coder of the Derived be *notify* of this change *even* when alias is used.I was *not* referring to my earlier suggestions about new pair of keywords at all. Unless that solved this issue, but it does NOT. I am trying to show that is what he is trying to ask: *How* would the coder of the Derived be *notify* of this change *even* when alias is used. I begin to see why hijacking is a problem in a inheritance tree, more clearly with this example posted by Kagamin. If someone messes the top of the tree, that is going to be a big problem. In javac there is such warning. But, this example, there does not seems to have one for D.I agree it is a possible case for hijacking, but I don't think it'scommon enough to require more syntax. May I ask, if there is any factual statistical calculations done or just purely manual 'observational'. -- Matthew Ong email: ongbp yahoo.com
Jun 04 2011