Skip to main content
http://meta.programmers.stackexchange.com/a/7403/31260
Source Link
gnat
  • 20.8k
  • 29
  • 115
  • 294

Also, what happendshappens if a class imprints two classes which have the same method? In that case the compiler would detect it and force the class to define an override of that method (where you could chose if you wanted to call either imprinted class or both)

SidenoteSide note - Why is this different from multiple inheritance

By the terminology sofarso far you might already confused. So what happens if ClassB inherits both from ClassA and another ClassC. I bet both programmers and compilers will be scratching their heads.

Also, what happends if a class imprints two classes which have the same method? In that case the compiler would detect it and force the class to define an override of that method (where you could chose if you wanted to call either imprinted class or both)

Sidenote - Why is this different from multiple inheritance

By the terminology sofar you might already confused. So what happens if ClassB inherits both from ClassA and another ClassC. I bet both programmers and compilers will be scratching their heads.

Also, what happens if a class imprints two classes which have the same method? In that case the compiler would detect it and force the class to define an override of that method (where you could chose if you wanted to call either imprinted class or both)

Side note - Why is this different from multiple inheritance

By the terminology so far you might already confused. So what happens if ClassB inherits both from ClassA and another ClassC. I bet both programmers and compilers will be scratching their heads.

edited body; added 23 characters in body
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69
[imprint List<Person> as PeopleList]peopleList]
public class People : PersonBase 
{
    public void SomeMethod()
    {
        DoSomething(this.Count); //Count is from List
    }
}

 //Now People can be treated as an List<Person>
 People people = new People();
 foreach(Person person in people)
 {
  ...
 }

PeopleList herepeopleList is an lias is usedalias/variablename (of your choice)used internally to alias the instance but can be skipped if not needed. One thing that's useful is to override an imprinted method, that could be achieved with the ordinary override syntax

public override void Add(Person person)
{ 
    DoSomething();
    PersonListpersonList.Add(person); 
}
[imprint List<Person> as PeopleList]
public class People : PersonBase 
{
    public void SomeMethod()
    {
        DoSomething(this.Count); //Count is from List
    }
}

 //Now People can be treated as an List<Person>
 People people = new People();
 foreach(Person person in people)
 {
  ...
 }

PeopleList here is an lias is used internally to alias the instance but can be skipped if not needed. One thing that's useful is to override an imprinted method, that could be achieved with the ordinary override syntax

public override void Add(Person person)
{ 
    DoSomething();
    PersonList.Add(person); 
}
[imprint List<Person> as peopleList]
public class People : PersonBase 
{
    public void SomeMethod()
    {
        DoSomething(this.Count); //Count is from List
    }
}

 //Now People can be treated as an List<Person>
 People people = new People();
 foreach(Person person in people)
 {
  ...
 }

peopleList is an alias/variablename (of your choice)used internally to alias the instance but can be skipped if not needed. One thing that's useful is to override an imprinted method, that could be achieved with the ordinary override syntax

public override void Add(Person person)
{ 
    DoSomething();
    personList.Add(person); 
}
added 41 characters in body
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69

note that the above is functional equivalent (and could be rewritten by the compiler) to:

note that the above is functional equivalent to:

note that the above is functional equivalent (and could be rewritten by the compiler) to:

added 5 characters in body
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69
Loading
added 24 characters in body
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69
Loading
added 136 characters in body
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69
Loading
added 1414 characters in body; added 189 characters in body
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69
Loading
Source Link
Homde
  • 11.1k
  • 3
  • 42
  • 69
Loading