1

Topic: Difficult (multiclass) inheritance and polymorphism - is possible or not?

Difficult (multiclass) inheritance and polymorphism - is possible or not? When I faced earlier class inheritance and polymorphism it was or, 1)  what that of new methods in descendant class which was not in a class-ancestor. (Normal inheritance). 2) redefinition of some methods declared in base class as virtual, (normal polymorphism), and  methods remained identical. And whether it is possible to inherit at once set of the bound classes? I.e. as though the whole project from the coherent classes, will be inherited from the basic project, the same classes, everyone in the set is inherited from a class-prototype in the basic project. That it was more clear that means, 1) we simplify the task to a limit - the set from 2 classes, should be inherited from other set from 2 classes. (In practice if there is such possibility with two it it is possible though 10 though 100 though any amount of classes in set to inherit). 2) I will write on -C# language that it was more clear that I mean. We admit, a certain project with title Module which for simplicity, consists of 2 classes earlier has been written. Later, we need to inherit these two classes in project Special which as though, expands Module-project possibilities.//------------------------------//It turns out, in the elementary variant, project Module, let us assume, consisted of two efficient classes. public class ModuleEntity//a certain essence in basic project Module {public int ab; public int cd;//certain fields describing essence} public class ModuleAlgorithmic//a certain essence in basic project Module {public ModuleEntity entity; public virtual ModuleEntity [] AlgorithmOfModule (ModuleEntity param) {//...} }//------------------------------//As it is necessary to inherit at once two classes. In new project Special. public class SpecialEntity: ModuleEntity//a certain essence in basic project Module. Inheritance of this class clearly. {public int ef;//well and it is clear, will be accessible ab, cd from ModuleEntity}//------------------------------ And here further, we need to inherit class SpecialAlgorithmic from ModuleAlgorithmic, yes so that 1) its unique field ModuleEntity entity; it became simple a field  type, SpecialEntity entity; 2) Method AlgorithmOfModule - needs to be redefined (override), yes so that its signature "almost same", but not absolutely - this method should accept already  links on SpecialEntity instead of ModuleEntity. I.e. how to write that that of type such (I result in pseudo-language, but it should be clear that means). public class SpecialAlgorithmic: ModuleAlgorithmic//a certain essence in basic project Module {public SpecialEntity entity: override ModuleEntity entity;//override field from ModuleAlgorithmic class - field entity public override SpecialEntity [] AlgorithmOfModule (SpecialEntity param): ModuleEntity [] AlgorithmOfModule (ModuleEntity param) {//...} }//------------------------------ That in that case turns out? We admit at us the first project, with classes ModuleEntity, ModuleAlgorithmic - completely efficient, and deduces a certain result after ModuleEntity param = new ModuleEntity (/*... */); ModuleEntity modEnt = new ModuleEntity (/* parameters creating object */); ModuleAlgorithmic modAlg = new ModuleAlgorithmic (modEnt);//accepting modEnt, writes down in the field entity ModuleEntity [] result = modAlg. AlgorithmOfModule (param)//where param - too ModuleEntity//we need to receive just the same result if it is replaceable in this unit from 4 lines, all "Module" on "Special" SpecialEntity param = new SpecialEntity (/*... */); SpecialEntity modEnt = new SpecialEntity (/* parameters creating object */);//here problems are not present - the field int ef is inherited and added; SpecialAlgorithmic modAlg = new SpecialAlgorithmic (modEnt);//accepting modEnt, writes down in the field entity!! But already in SpecialEntity entity: Which override (not ModuleEntity type) SpecialEntity [] result = modAlg. AlgorithmOfModule (param)//where param - too ModuleEntity, but is more exact -  type SpecialEntity from ModuleEntity//------------------------------ would Seem, all is simple - inherited SpecialEntity from ModuleEntity, adding it a field (here problems are not present). The second - inherited SpecialAlgorithmic from ModuleAlgorithmic that finally it was possible to cause just the same code, only replacing words ' Module ' on ' Special '. The virtual method AlgorithmOfModule will be too as it is necessary, is redefined. BUT!! Here a hitch - 1) that is necessary still the first - to redefine its signature i.e. that the method accepted and returned objects of other type, let and ! 2) a field superfluous entity - too to create NOT the VARIANT - more storages will occupy (we admit algorithm has strongly rests against storage) so it is necessary to redefine an internal FIELD. If who understood, prompt, how means C# and.NET (and the C ++ can also) - it is possible to solve such task of "difficult multiclass inheritance"? That superfluous fields in a class-wrapper not to create, and a method to redefine with the legacy signature. If it is possible, the whole projects with many coherent classes can be inherited, redefining only the necessary part, and in the causing code, it will be necessary to replace only a project title-hider as at us - replaced ' Module ' on ' Special '. What  "designing templates" the similar allow? In advance, thanks.

2

Re: Difficult (multiclass) inheritance and polymorphism - is possible or not?

Hello, SergeyY, you wrote: SY> BUT!! Here a hitch - 1) that is necessary still the first - to redefine its signature i.e. that the method accepted and returned objects of other type, let and ! SY> 2) a field superfluous entity - too to create NOT the VARIANT - more storages will occupy (we admit algorithm has strongly rests against storage) so it is necessary to redefine an internal FIELD. You about ?

3

Re: Difficult (multiclass) inheritance and polymorphism - is possible or not?

Hello, the Daisy wheel, you wrote: Hello, SergeyY, you wrote: SY>> BUT!! Here a hitch - 1) that is necessary still the first - to redefine its signature i.e. that the method accepted and returned objects of other type, let and ! SY>> 2) a field superfluous entity - too to create NOT the VARIANT - more storages will occupy (we admit algorithm has strongly rests against storage) so it is necessary to redefine an internal FIELD. You about ? We have completely an efficient project with a title "Module", and classes ModuleEntity, ModuleAlgorithmic, any  in it is not present. How to inherit at once the whole project, in this case - in class SpecialAlgorithmic - the field, but with type redefinition is inherited, and the method (override) that is redefined also the signature was from derived types. More shortly in the causing code that there was all the same, except word changeover ' Module ' on ' Special '.

4

Re: Difficult (multiclass) inheritance and polymorphism - is possible or not?

Hello, SergeyY, you wrote: SY> How to inherit at once the whole project, in this case - in class SpecialAlgorithmic - the field, but with type redefinition is inherited, SY> and the method (override) that is redefined also the signature was from derived types. So it is impossible. It is impossible to redefine a field with new type or a method with other signature. PS if there is an access to source codes of the first project - change types on .

5

Re: Difficult (multiclass) inheritance and polymorphism - is possible or not?

Hello, the Daisy wheel, you wrote: So it is impossible. It is impossible to redefine a field with new type or a method with other signature. Actually, about a method, we can redefine it with the same signature since the type is inherited the pseudocode of class SpecialAlgorithmic - public override SpecialEntity [] AlgorithmOfModule (SpecialEntity param): ModuleEntity [] AlgorithmOfModule (ModuleEntity param) {//...} } Will be approximately such public override ModuleEntity [] AlgorithmOfModule (ModuleEntity param) {SpecialEntity param2 = (SpecialEntity) param;//the transferred object transformed to derived type explicitly.//... return (ModuleEntity []) result;//and that that is returned - transformed reversely to basic}} Actually the same it would be possible to make at level of the compiler of OOP-language that in the causing code, could use simply a method with the signature of types which are inherited, and not to write explicit type conversions (SpecialEntity) param. I.e. as it is written above, simply correctly to declare a method.-------------------- public override SpecialEntity [] AlgorithmOfModule (SpecialEntity param): ModuleEntity [] AlgorithmOfModule (ModuleEntity param) {//...} } And in the causing code simply to cause it as though it accepted SpecialEntity instead of MoluleEntity - SpecialEntity param = new SpecialEntity (/*... */); SpecialEntity modEnt = new SpecialEntity (/* parameters creating object */); SpecialAlgorithmic modAlg = new SpecialAlgorithmic (modEnt); SpecialEntity [] result = modAlg. AlgorithmOfModule (param);-------------------- I.e. I offered a variant which if has been implemented at level of the compiler of OOP-language, it would expand OOP possibilities. The whole project could be inherited from another, and in the causing code simply to change  objects of all created classes. The second - field redefinition in a heritable class. Here in what a difference? The first - we inherited one class from another, public class ModuleEntity//a certain essence in basic project Module {public int ab; public int cd;//certain fields describing essence} public class SpecialEntity: ModuleEntity//a certain essence in basic project Module. Inheritance of this class clearly. {public int ef;//well and it is clear, will be accessible ab, cd from ModuleEntity} I.e. fields ab, cd there was that that new. In what the basic difference with that if the object of this class will be a field in other class, public class ModuleAlgorithmic//a certain essence in basic project Module {public ModuleEntity entity;} public class SpecialAlgorithmic: ModuleAlgorithmic//a certain essence in basic project Module {public SpecialEntity entity: override ModuleEntity entity;//override field from ModuleAlgorithmic class - field entity} Actually, it would be desirable the same i.e. that the field entity in class SpecialAlgorithmic - simply extended, and it was not necessary to create the new. (The data in derivative class SpecialEntity - ab in the same way extended and cd - remains in it) If it cannot be made, it is necessary to create other field in class SpecialAlgorithmic, with ab cd ef, and "superfluous" entity with ab, cd will already not be used and it will be simple to occupy superfluous storage that in algorithm, sensitive to storage, will be an essential lack. Therefore, and it is interesting to eat, maybe, what that possibilities in language C# or a C ++ to implement similar difficult "multiclass" inheritance + polymorphism? There are any templates of designing, can exists also such, with the approximate possibilities? It would be desirable simply, implementing these two projects, to have possibility in the causing code simply to replace a word ' Module ' with a project title, (in the resulted case it was ' Special ') and to receive the efficient program.

6

Re: Difficult (multiclass) inheritance and polymorphism - is possible or not?

Change types on . If it is a unique variant how to use for example?  like, allow to substitute simply any type, and that that one is inherited from another is an advantage in them is not implemented?

7

Re: Difficult (multiclass) inheritance and polymorphism - is possible or not?