From syntactic definition the level sees Abstract Class and Interface
In syntactic level, java language defines way to what Abstract Class and Interface gave out to differ, with defining the name is the abstraction of Demo below kind for will explain this kind differs.
The means definition Demo of use Abstract Class is abstract kind means is as follows:
{ of Abstract Class DemoAbstract Void Method1();Abstract Void Method2();
…
}
The means definition Demo of use Interface is abstract kind means is as follows:
Interface Demo{Void Method1();Void Method2();
…
}
In Abstract Class means, demo can have his data member, also can have the member method that is not Abstract, and in the implementation in Interface means, the data member that cannot be revised what Demo can have a static state only (must be Static Final namely, general in Interface nevertheless adventitious justice data member) , all member methods are Abstract. In some sense, interface is the Abstract Class of a kind of special form.
From the point of the angle of process designing, abstract Class and Interface can use the idea that realizes "design By Contract" . But there still are a few distinctions above specific use.
Above all, abstract Class is denotive in Java language it is a kind of successive relation, kind can use successive relationship only (because Java does not support,accede more- - ) of mutually explanatory or synonymous characters. But, kind can realize many Interface however. Perhaps, the architect that this is Java language is considering Java to a multiple and successive kind when back an aspect eclectically.
Next, in the definition of Abstract Class, we can gift acquiescent behavior of the method. But in the definition in Interface, the method cannot have acquiescent action however, to bypass this is restricted, must use entrust, but this meeting increases a few complexity, can cause very big trouble sometimes.
In abstraction kind in cannot define acquiescent behavior to still exist another more serious problem, that may be caused namely safeguard the trouble that go up. Because if think later,be revised kind interface (pass Abstract Class commonly or Interface will express) in order to get used to new case (for instance, new parameter is added in adding new method to perhaps give the method that already used) when, with respect to can exceeding trouble, the likelihood should spend a lot of time (to derive kind a lot of circumstances, particularly such) . But if the interface comes true through Abstract Class, need so possibly to revise a definition only the acquiescent behavior in Abstract Class is OK.
Same, if cannot be in abstract kind in define acquiescent conduct, can bring about same methodological implementation to appear in this abstraction kind each derive kind in, disobeyed "one Rule, one Place" principle, cause code to repeat, go against likewise the following safeguard. Accordingly, great caution wants when undertaking choosing between Abstract Class and Interface.
Previous 1 23 4 5 Next