Links

Categories

Tags


« | Main | »

Testing mix-in classes

By Jewe | January 1, 2015

Testing mix-in classes.

class YvesLaurentJacket
{
    method YvesLaurentJacket(string color, string material)
    {
        jacket_vendor = "Yves Laurent";
        jacket_color = color;
        jacket_material = material;
    }
    method PrintJacket()
    {
        print({ "Jacket: ", jacket_vendor, " ", jacket_color, " ", jacket_material, "\n" });
    }
    string jacket_vendor;
    string jacket_color;
    string jacket_material;
}

class NorthfaceJacket
{
    method NorthfaceJacket(string material)
    {
        jacket_vendor = "Northface";
        jacket_material = material;
    }
    method PrintJacket()
    {
        print({ "Jacket: ", jacket_vendor, " ", jacket_material, "\n" });
    }
    string jacket_vendor;
    string jacket_material;
}

class GucciShoes
{
    method GucciShoes(string color)
    {
        shoes_vendor = "Gucci";
        shoes_color = color;
        shoes_material = "Crocodile";
    }
    method PrintShoes()
    {
        print({ "Shoes: ", shoes_vendor, " ", shoes_color, " ", shoes_material, "\n" });
    }
    string shoes_vendor;
    string shoes_color;
    string shoes_material;
}

class AdidasShoes
{
    method AdidasShoes(string color)
    {
        shoes_vendor = "Adidas";
        shoes_color = color;
    }
    method PrintShoes()
    {
        print({ "Shoes: ", shoes_vendor, " ", shoes_color, "\n" });
    }
    string shoes_vendor;
    string shoes_color;
}

class ArmaniPants
{
    method ArmaniPants(string material, string color)
    {
        pants_vendor = "Armani";
        pants_material = material;
        pants_color = color;
    }
    method PrintPants()
    {
        print({ "Pants: ", pants_vendor, " ", pants_color, " ", pants_material, "\n" });
    }
    string pants_vendor;
    string pants_material;
    string pants_color;
}

class CavalliPants
{
    method CavalliPants(string material, string color, string extras)
    {
        pants_vendor = "Robert Cavalli";
        pants_material = material;
        pants_color = color;
        pants_extras = extras;
    }
    method PrintPants()
    {
        print({ "Pants: ", pants_vendor, " ", pants_color, " ", pants_material, " ",
            pants_extras, "\n" });
    }
    string pants_vendor;
    string pants_material;
    string pants_color;
    string pants_extras;
}

class Judy inherits YvesLaurentJacket, AdidasShoes, ArmaniPants
{
    method Judy() inherits
        YvesLaurentJacket("Olive", "Leather"),
        AdidasShoes("Pink"),
        ArmaniPants("Satin", "Yellow")
    {
    }

    method Print()
    {
        println("Judy's attire:");
        PrintJacket();
        PrintShoes();
        PrintPants();
    }
}

class Rick inherits NorthfaceJacket, GucciShoes, CavalliPants
{
    method Rick() inherits
        NorthfaceJacket("Polyacryl"),
        GucciShoes("Black"),
        CavalliPants("Jeans", "Blue", "iPad pocket")
    {
    }

    method Print()
    {
        println("Rick's attire:");
        PrintJacket();
        PrintShoes();
        PrintPants();
    }
}

function string main(const string[] args)
{
    Judy judy;
    judy.Print();

    Rick rick;
    rick.jacket_vendor = "Jack Wolfskin"; // let's rebrand rick's jacket :)
    rick.Print();

    /*
        Judy's attire:
        Jacket: Yves Laurent Olive Leather
        Shoes: Adidas Pink
        Pants: Armani Yellow Satin
        Rick's attire:
        Jacket: Jack Wolfskin Polyacryl
        Shoes: Gucci Black Crocodile
        Pants: Robert Cavalli Blue Jeans iPad pocket
    */

    return null;
}

Topics: code examples | Comments Off on Testing mix-in classes

Comments are closed.