All files clockFactories.ts

21.42% Statements 6/28
100% Branches 0/0
11.76% Functions 2/17
21.42% Lines 6/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74    2x                   3x 3x   3x 3x                                                                                                             2x    
import IClock from './IClock'
// the raw materials
import * as Clocks from './clocks'
 
 
interface AbsClockFactory {
    clockType : string
    instance() : IClock 
    numCreated() : number
}
 
class ClockFactory1 implements AbsClockFactory {
    clockType = "Clock1"
    numcreated = 0    
    public instance() : IClock {
        this.numcreated++;
        return new Clocks.Clock1}
    public numCreated() : number {return this.numcreated}
}
 
class ClockFactory2 implements AbsClockFactory {
    clockType = "Clock2"
    numcreated = 0    
    public instance() : IClock {
        this.numcreated++;
        return new Clocks.Clock2}
    public numCreated() : number {return this.numcreated}
}
 
class ClockFactory3 implements AbsClockFactory {
    clockType = "Clock3"
    numcreated = 0    
    public instance() : IClock {
        this.numcreated++;
        return new Clocks.Clock3}
    public numCreated() {return this.numcreated}
}
 
// these classes all share some code, so you could make
// an abstract class and have them all inherit from it, 
 
abstract class ClockFactorySuperClass implements AbsClockFactory {
    abstract clockType: string
    protected numcreated = 0    
    public abstract instance() : IClock 
    public numCreated() {return this.numcreated}
}
 
class ClockFactory1asSubclass extends ClockFactorySuperClass
 implements AbsClockFactory {
    clockType = "Clock1" 
    public instance() : IClock {
        this.numcreated++;
        return new Clocks.Clock3}
}
class ClockFactory2asSubclass extends ClockFactorySuperClass
 implements AbsClockFactory {
    clockType = "Clock3" 
    public instance() : IClock {
        this.numcreated++;
        return new Clocks.Clock3}
}
class ClockFactory3asSubclass extends ClockFactorySuperClass
 implements AbsClockFactory {
    clockType = "Clock3" 
    public instance() : IClock {
        this.numcreated++;
        return new Clocks.Clock3}
}
// choose which of the factories to export, but don't 
// tell anybody which one it is.
export default ClockFactory1
// export default ClockFactory2
// export default ClockFactory3