Skip to content

Interface declaration

ALexeyP0708 edited this page Jul 2, 2020 · 3 revisions

An example of direct inheritance.

class MyInterface {
	method(){}
	method2(){}
	get react(){}
	set react(){}
}
let MyInterface.prototype.prop={
	types:'mixed'
};
MyInterface.isInterface=true;
MyInterface2 extends MyInterface{
/* redefine criteria MyInterface for "method2" */
	method2(){ 
		return:{types:['string',undefined]}
	}
	method3(){} 
	/* redefine criteria MyInterface for react (get) 
	- it is forbidden to declare if "get" is not declared in the parent interface*/
	get react(){} 
	
	/* redefine criteria MyInterface for react (set) 
	- it is forbidden to declare if "set" is not declared in the parent interface*/
	set react(){} 
}
MyInterface2.isInterface=true;
MyClass extends MyInterface2{
	/*Must be declared according to MyInterface*/
	method(){}
	
	/*Must be declared according to MyInterface*/
	method2(){
		return 'Hello';
	}
	
	/*Must be declared according to MyInterface2*/
	method3(){}
	
	/*Must be declared according to MyInterface2
		-forbidden to declare if "get" is not declared in the interface
	*/
	get react(){} 

	/*Must be declared according to MyInterface2
		-forbidden to declare if "set" is not declared in the interface
	*/
	set react(){}
}

/*Must be declared according to MyInterface*/
MyInterface.prototype.prop='Hello';
InterfaceManager.implementInterfaces(MyClass);

Direct inheritance

Inheriting Interfaces through the semantics of the JS (ES6) language. With _ direct inheritance_, the assembly will be done through ** interface comparison **.

class MyInterface{
}
MyInterface.isInterface=true;

class MyInterface2 extends MyInterface{

}
MyInterface2.isInterface=true;

class MyClass extends MyInterface2{

}
/* use for abstract classes */
InterfaceManager.extendIntefaces(MyClass);

// or

/* use for full classes. Validation will occur */
InterfaceManager.implementInterfaces(MyClass);

Indirect Inheritance

Inheritance of interfaces through special methods

class MyInterface{
}
MyInterface.isInterface=true;

class MyInterface2{
}
MyInterface2.isInterface=true;

class MyClass {
}
/*
Inheritance occurs by listing the Interfaces in InterfaceManager.extendIntefaces/InterfaceManager.implementInterfaces for the class MyClass
*/
InterfaceManager.extendIntefaces(MyClass,MyInterface,MyInterface2);

// or

InterfaceManager.implementInterfaces(MyClass,MyInterface,MyInterface2);

Interface rule generation

The methods InterfaceManager.extendIntefaces, InterfaceManager.implementInterfaces, InterfaceManager.expandIntefaces generate interface rules and assemble class members. Methods can be used at any stage of declaring interfaces or classes .

class MyInterface{}
MyInterface.isInterface=true;
InterfaceManager.extendIntefaces(MyInterface);

class MyInterface2 extends MyInterface {
}
MyInterface2.isInterface=true;
InterfaceManager.extendIntefaces(MyInterface2);

class MyInterface3 {}
MyInterface3.isInterface=true;
class MyClass{}
InterfaceManager.extendIntefaces(MyClass,MyInterface2,MyInterface3);

class MyInterface4{}
MyInterface4.isInterface=true;

class MyClass2 extends MyClass{}
InterfaceManager.implementIntefaces(MyClass2,MyInterface4);

If you need to look interface rules for debugging:

let rules;
rules=InterfaceManager.extendIntefaces(MyClass2);
// or
rules=InterfaceManager.implementIntefaces(MyClass2);
// or
rules=InterfaceManager.getInterfaceData(MyClass2);
console.log(rules);