All files / src factories.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 10/10

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    20x         20x               20x                                           20x 133x 2x   131x   20x   20x       20x  
import * as Interface from './interface';
import * as Types from './types';
import {Connection} from './controller/connection';
// ==================================== ConnectionFactory =====================================//
/**
 * Класс-шаблон, который предоставляет возможность другим классам создавать объект типа Interface.Connection
 */
class ConnectionFactory<ConnectionType extends Interface.Connection> {
    private connectionClass: new (outSource: Types.Sources, arg2?: (Types.Sources|Types.SourcesArray)) => ConnectionType;
 
    /**
     * Конструктор фабрики, принимает класс, который необходимо создать
     * @param connectionClass класс который необходимо создать
     */
    constructor(connectionClass: new (outSource: Types.Sources, arg2?: (Types.Sources|Types.SourcesArray)) => ConnectionType) {
        this.connectionClass = connectionClass;
    }
 
    /**
     * Перегрузка метода создания Сonnection подробнее см. {@link Connection}
     */
    create(outSource: Types.Sources): ConnectionType;
    /**
     * Перегрузка метода создания Сonnection подробнее см. {@link Connection}
     */
    create(outSource: Types.Sources, inSource: Types.Sources): ConnectionType;
    /**
     * Перегрузка метода создания Сonnection подробнее см. {@link Connection}
     */
    create(outSource: Types.Sources, inSourceArray: Types.SourcesArray): ConnectionType;
 
    /**
     * Перегрузка метода создания Сonnection подробнее см. {@link Connection}
     * @param outSource
     * @param arg2
     * @returns элемент Connection
     */
    create(outSource: Types.Sources, arg2?: (Types.Sources|Types.SourcesArray)): ConnectionType {
        if (arg2){
            return new this.connectionClass(outSource, arg2);
        }
        return new this.connectionClass(outSource);
    }
}
// ==================================== ConnectionFactory =====================================//
const Factories = {
    Connection: new ConnectionFactory<Connection>(Connection)
};
 
export {Factories};