Links

Categories

Tags


« | Main | »

interface factorization

By Jewe | January 2, 2014

interface Person
{
    method Person(string n);
    method Print();
}

class ImpolitePerson implements Person
{
    method ImpolitePerson(string n) { name = n; }
    method Print() { println(name); }
    string name;
}

class PolitePerson implements Person
{
    method PolitePerson(string n) { name = n; }
    method Print() { println("Hello, I am " + name); }
    string name;
}

function main()
{
    Person[] factory = new Person("Sally");
    factory[0].Print(); // prints "Sally"
    factory[1].Print(); // prints "Hello, I am Sally"
}

Topics: code examples | Comments Off on interface factorization

Comments are closed.