Skip to content

Rules for declaring and comparing Criteria for inheriting an Interface

ALexeyP0708 edited this page Jul 5, 2020 · 1 revision

Property criteria (CriteriaPropertyType template)

The criteria for the property of the child Interface must match the property criteria of the parent Interface.

class TypeA{}
class TypeA1{}
class TypeB extends TypeA{}
class TypeC extends TypeA{}
class TypeD extends TypeA{}
class MyInterface {}
MyInterface.prototype.prop={
	types:['number','string','object','undefined','null'], 
	includes:[1,2,3,4,5,'Hello',undefined,null,TypeA],
	excludes:[TypeB,TypeC].
};
MyInterface.prototype.prop2={}; // равносильно {types:'mixed'}
MyInterface.isInterface=true;

class MyInterface2 extends MyInterface {

}
MyInterface2.prototype.prop={
	/* 
	the parameter must not be empty and have values ​​from the property criteria (types) 
	of the parent interface
	*/
	types:['object','undefined','null'], // compare success
	
	/*
	the parameter must not be empty and have values ​​from the property criteria (includes)
	of the parent interface
	*/
	includes:[undefined,null,TypeA],//compare success
	
	/*
	The parameter must be compatible with the criteria (excludes)
	 of the parent interface and can be expanded.
	If the established types do not allow to enter the value
	from the criteria (excludes) specified in the parent interface,
	then this value is not entered.
	*/
	excludes:[TypeB,TypeC,TypeD] // compare success
};
MyInterface2.isInterface=true;
InterfaceManager.extendInterfaces(MyInterface2);

class MyInterface3 extends MyInterface {

}
MyInterface3.prototype.prop={
	types:types:['function','undefined','null'], // compare error - does not expect function
	includes:[undefined,null,TypeA1],// compare error - does not expect TypeA1
	excludes:[TypeB] // compare error - Missing TypeC
};
MyInterface3.isInterface=true;
InterfaceManager.extendInterfaces(MyInterface3);

Method Criteria(CriteriaMethodType template)

class MyInterface{
	method(){
		return{
			arguments:[
				
				{
					types:'number'
				}
			],
			return:{
				types:'number'
			}
			 
		}
	}
}
MyInterface.isInterface=true;

class MyInterface2 extends MyInterface{
	method(){
		return{

			/*
			argument criteria must be listed according to the criteria of the parent interface, 
			and new arguments can be added.
			Method argument criteria comparisons are comparable to CriteriaPropertyType criteria 
			comparison rules.
			*/
			arguments:[
				{
					types:'number'
				},
				{
					types:'number'
				}
			],
			
			/* 
			Comparison of the criteria of the return value of the method are comparable to the rules of 
			comparison of the criteriaCriteriaPropertyType 
			*/
			return:{
				types:'number'
			}
			 
		}
	}
}
MyInterface2.isInterface=true;
InterfaceManager.extendInterfaces(MyInterface2);

Reactive property criteria (CriteriaReactType template)

class MyInterface{
	get react(){ // CriteriaPropertyType template
		return:{
			types:['number','string']
		} 
	}
	set react(v){ // CriteriaPropertyType template
		return{
				types:'number'
			} 
		}
	}
	get react2(){ // CriteriaMethodType {return:{}} template
		return{
			return:{
				types:'number'
			} 
		}
	}
	set react2(v){ // CriteriaMethodType {arguments:[{}]} template
		return{
			arguments:[{
				types:'number'
			}] 
		}
	}
	set react3(value){ //alternative "set" criteria
		value.types=['number'];
	}
}
MyInterface.isInterface=true;
class MyInterface2 extends MyInterface{
	/*  if get is declared in the parent Interface, 
	then get must be declared in the child interface, 
	otherwise it is forbidden to declare */
	
	get react(){ // CriteriaPropertyType template
		return:{
			types:'number'
		} 
	}

	/*   if set is declared in the parent Interface, 
	then set must be declared in the child interface, 
	otherwise it is forbidden to declare
	*/
	set react(v){ // CriteriaPropertyType template
		return {
				types:'number'
			} 
		}
	}
}
MyInterface2.isInterface=true;
InterfaceManager.extendInterfaces(MyInterface2);