Position:Home>JAVA Development> The abstraction in detailed and analytic Java kind the distinction with interfac
The abstraction in detailed and analytic Java kind the distinction with interfac
From;  Author:Stand originally


From the design concept level sees Abstract Class and Interface

The distinction that discussed Abstract Class and Interface with the angle of process designing basically is defined from grammar above, the distinction of these levels is lower administrative levels, nonessential. This bar will from another level: Abstract Class and Interface place mirror reflective design concept, will analyse the distinction of both. The author thinks, the essence that undertakes from this level ability understands both concept analytic is in.

Had mentioned in front, abstract Class reflected a kind of successive concern in Java language, want to make successive relationship reasonable, father kind with derive kind between must put in "is-a" relation, namely father kind with derive kind in the concept should be identical substantially. To Interface criterion otherwise, the person come true that does not beg Interface and Interface definition are in the concept is consistent substantially, it is the bond that realized Interface definition merely just. To make discuss facilitating understanding, a simple example will be passed below undertake demonstrative.

Consider a such case, there is an abstract idea about Door in our problem domain suppose, this Door is had carry out two movements Open and Close, right now we can pass Abstract Class or the type that Interface will come to define to express this abstraction idea, definition means is shown as follows respectively:

Means of use Abstract Class defines Door:
Abstract Class Door{Abstract Void Open();Abstract Void Close() ;
}

Use Interface means defines Door:
Interface Door{Void Open();Void Close();
}

Other and specific Door type is OK the Door that means of Extends use Abstract Class defines or the Door that means of Implements use Interface defines. Seem to use Abstract Class and Interface to do not have big distinction it seems that.

If ask now,Door has the function that call the police even. How should we design kind of structure in the light of this example (in this exemple, basically be to reveal Abstract Class and Interface to be mirrorred in the distinction on design concept, was the problem that other side has nothing to do done simplify or oversight) ? Possible solution gives enumerate below, the plan that differs to these from design concept level undertakes an analysis.

Solution one:

An Alarm method adds simply in the definition of Door, following:
Abstract Class Door{Abstract Void Open();Abstract Void Close() ; Abstract Void Alarm();
}

Or
Interface Door{Void Open();Void Close();Void Alarm();
}

The definition means of the AlarmDoor that has warning function so is as follows:
Class AlarmDoor Extends Door{Void Open(){…}Void Close(){…}Void Alarm(){…}
}

Or
{ of Class AlarmDoor Implements DoorVoid Open(){…}Void Close(){…}Void Alarm(){…}
Previous 1 2 34 5 Next