0.0.2 • Published 9 years ago

pingo v0.0.2

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
9 years ago

Build Status NPM

pingo

pingo is a suite of decorators.

Releases

See the changelog for more information.

Project Site

The project site, see (2) under resources below, provides more insight into the project, including test coverage reports and API documentation.

Contributing

You are very welcome to propose changes and report bugs, or even provide pull requests on github.

See the contributing guidelines for more information.

Contributors

Building

See build process and the available build targets for more information on how to build this.

See also development dependencies and on how to deal with them.

Installation

npm --save pingo

Runtime Dependencies

The dependencies denoted in italics must be provided by the using project.

Documentation

@abstract

The @abstract decorator can be used for decoration of both classes and methods.

Abstract classes cannot be instantiated and invocation of abstract methods will result in an error.

Derived classes must implement all abstract methods or otherwise instantiation of the derived class will result in an error.

import {abstract} from 'pingo';


@abstract
class AbstractAnimal
{
    constructor(name)
    {
        this._name = name;
    }

    get name()
    {
        return this._name;
    }

    @abstract
    static family() {}

    @abstract
    specialMove() {}
}


@abstract
class AbstractSpeakingAnimal extends AbstractAnimal
{
    constructor(name, sound)
    {
        super(name);
    
        this._sound = sound;
    }

    get sound()
    {
        return this._sound;
    }

    speak()
    {
        return `${this.name}: ${this.sound}`;
    }
}


class Cat extends AbstractSpeakingAnimal
{
    constructor(name)
    {
        super(name, 'meooww');
    }

    static family()
    {
        return 'Feline';
    }

    specialMove()
    {
        return 'sleep';
    }
}


class IncompleteImpl extends AbstractAnimal
{}


const cat = new Cat('felicitas');
console.log(cat.speak());
// felicitas: meooww
console.log(cat.specialMove());
// sleep

new AbstractSpeakingAnimal();
// TypeError: abstract class AbstractSpeakingAnimal cannot be instantiated

new IncompleteImpl();
// TypeError: abstract class IncompleteImpl cannot be instantiated

IncompleteImpl.family();
// Error: IncompleteImpl must implement abstract method ...

Similar Projects

Resources

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago