1

Topic: For what sharing on class and interface is necessary?

In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). Why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still?

2

Re: For what sharing on class and interface is necessary?

D> In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). Why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still? If in language there is no multiple inheritance to be inherited more favourably from that class which implements a maximum of necessary functionality. And all remaining - through interfaces

3

Re: For what sharing on class and interface is necessary?

Hello, developer, you wrote: D> In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). Why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still? In Java there is no multiple inheritance of classes. The class can have only one ancestor-class, but the set of ancestors-interfaces is admitted. The interface is as a matter of fact completely the abstract class to which cannot add not abstract method or a field casually then. You see the interface in the code and understand that it and will remain the interface. It is important, because the code permanently changes or otherwise the program will become all less and less useful.

4

Re: For what sharing on class and interface is necessary?

Hello, Vladek, you wrote: V> In Java there is no multiple inheritance of classes. The class can have only one ancestor-class, but the set of ancestors-interfaces is admitted. The interface is as a matter of fact completely the abstract class to which cannot add not abstract method or a field casually then. You see the interface in the code and understand that it and will remain the interface. It is important, because the code permanently changes or otherwise the program will become all less and less useful. I.e. the unique reason on which in Java interfaces (as separate concepts) it what in Java there is no multiple inheritance are entered? The abstract class can be made the same not changing - to declare it final.

5

Re: For what sharing on class and interface is necessary?

D> In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). The abstract classes - means of reusage of the code, and interfaces - means of the description of the contract. D> why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still? It is possible. For  abstractness - the interface after all as a matter of fact an is pure-abstract class without implementations and the data.

6

Re: For what sharing on class and interface is necessary?

D> I.e. the unique reason on which in Java interfaces (as separate concepts) it what in Java there is no multiple inheritance are entered? D> the abstract class can be made the same not changing - to declare it final. I do not know, how in , but the interface is pure abstraction, the arrangement on any functionality, independent of implementation. For example the bulb should have a cutout. Methods to switch on and off is an interface. To do by their button on a wall or the sensor which will react to driving or a sound is an individual question. Implementations can differ a heap of everything, be for three kilometers or in other application written in other language.

7

Re: For what sharing on class and interface is necessary?

Hello, developer, you wrote: D> In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). Why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still? In the end-ends in OOP came to a conclusion that inheritance == ANGRILY. For performance of conditions of the contract enough public signatures of methods and implementation of interfaces, and methods of objects to do public are optional. It leads to "plane" architectural decisions where interaction of objects is under construction under the circuit of the interfaces, which classes implement. And interfaces, in turn, are studied most carefully as they are responsible for representation of the protocol of interaction between objects-ENTITIES.

8

Re: For what sharing on class and interface is necessary?

Hello, developer, you wrote: the Interface is a contract which does not contain implementation. Its closest analog - purely abstract class, i.e. the class which is not containing implemented methods and fields. The normal abstract class can contain the code and the fields inherited by descendants. In addition to that in the absence of multiple inheritance, inheritance from interfaces begins a unique method to unite descendants in inheritance chains, interfaces are applied in modular testing (certainly if the code is written correctly, using DIP).

9

Re: For what sharing on class and interface is necessary?

Hello, developer, V>> In Java there is no multiple inheritance of classes. The class can have only one ancestor-class, but the set of ancestors-interfaces is admitted. D> I.e. the unique reason on which in Java interfaces (as separate concepts) it what in Java there is no multiple inheritance are entered? D> the abstract class can be made the same not changing - to declare it final. Technically yes, it is possible and so to say. In pluses for example interfaces without problems are replaced with the abstract classes. But not to lose polymorphism possibility, something should be. Interfaces there,  inheritance, multimethods... Sense in that it was possible to use equally varied objects, without reflecting on their specific type type in usage place (not to write a switch on type) multiple inheritance, or possibility  several interfaces that the same object could be used thus in different places.

10

Re: For what sharing on class and interface is necessary?

Hello, bnk, you wrote: bnk> In pluses for example interfaces without problems are replaced with the abstract classes. "Without problems" is a little  announcement. Therefore as "that such diamond-shaped inheritance" and "that such virtual inheritance" not each seigneur answered questions about 10 years ago. And one of principal causes of introduction of interfaces is a judgement of experience With ++ and the method to avoid  with diamond-shaped inheritance.

11

Re: For what sharing on class and interface is necessary?

Hello, developer, you wrote: D> In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). Why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still? Here that E.Troelsen in the book "writes the Programming language C# and the platform.Net 4.5" After chapter 6 learning the interface type can seem very similar to the abstract base class. Recall that when the class is marked as abstract, it can define any amount of the abstract members for provision of the polymorphic interface to all derived types. However even if the class really defines a dial-up of the abstract members, it also can define any amount of designers, data fields, not abstract members (with implementation), etc. On the other hand, interfaces can contain only determinations of the abstract members. The polymorphic interface installed by the abstract parent class, possesses one serious restriction: the members defined by the abstract parent class, are supported only by derived types. Nevertheless, in large program systems the numerous class hierarchies which do not have the general parent except for System are very often developed. Object. Considering that the abstract members in the abstract base class are applicable only to derived types, there is no method of adjustment of types in different hierarchies on support of the same polymorphic interface.

12

Re: For what sharing on class and interface is necessary?

Hello, developer, you wrote: D> In programming languages, for example, in Java, in addition to data types (class) are available also interfaces (interface). Why it is impossible to manage one only classes? After all there is a base class, there is the abstract class. For what it is necessary to enter interfaces still? Above already marked - . The class can have any predetermined behavior, and the interface is not present. Competent usage . Classes it is possible to consider on an example of pattern Template method when at us a certain desirable behavior is already put, and in successors we can redefine () behavior of separate methods. At designing of classes it is possible to use heuristics "that" and "as". "That" is . A class, "as" - the interface.