Escolar Documentos
Profissional Documentos
Cultura Documentos
Computational structures are defined by their meanings (semantics), while hiding away the details of
how they work. Abstraction tries to factor out details from a common pattern so that programmers can
work close to the level of human thought, leaving out details which matter in practice, but are
immaterial to the problem being solved. For example, a system can have several abstraction layers
whereby different meanings and amounts of detail are exposed to the programmer; low-level
abstraction layers expose details of the computer hardware where the program runs, while high-level
layers deal with the business logic of the program.
Abstraction captures only those details about an object that are relevant to the current perspective. For
instance, numbers are concepts in programming languages. Numbers can be represented in many
different ways in hardware and software, but, irrespective of how this is done, numerical operations will
obey similar rules.
Abstraction can apply to control or to data: Control abstraction is the abstraction of actions while data
abstraction is that of data structures.
In a programming language that exhibits polymorphism, objects of classes belonging to the same
hierarchical tree (i.e. inherited from a common base class) may possess functions bearing the same
name, but each having different behaviors.
As an example, let us assume there is a base class named Animals from which the subclasses Horse, Fish
and Bird are derived. Let us also assume that the Animals class has a function named Move, which is
inherited by all subclasses mentioned. With polymorphism, each subclass may have its own way of
implementing the function. So, for example, when the Move function is called in an object of the Horse
class, the function might respond by displaying trotting on the screen. On the other hand, when the
same function is called in an object of the Fish class, swimming might be displayed on the screen. In the
case of a Bird object, it may be flying.
In effect, polymorphism trims down the work of the developer because he can now create a sort of
general class with all the attributes and behaviors that he envisions for it. When the time comes for the
developer to create more specific subclasses with certain unique attributes and behaviors, the
developer can simply alter code in the specific portions where the behaviors will differ. All other
portions of the code can be left as is.
Sa isang programming language na nagpapakita polymorphism , mga bagay
ng mga klase sa pag-aari ng parehong hierarchical puno (ibig sabihin,
minana mula sa isang karaniwang base klase ) ay maaaring nagtataglay
ng pag-andar tindig katulad na pangalan, ngunit ang bawat pagkakaroon
ng iba't ibang pag-uugali.
Bilang halimbawa , sabihin sa amin ipagpalagay mayroong isang batayang
klase na may pangalang Hayop kung saan ang subclasses ng Kabayo , Isda
at Bird ay nagmula . Hayaan ipinapalagay rin sa amin na ang Hayop
klase ay isang function na may pangalang Ilipat , na minana sa
pamamagitan ng lahat ng subclasses nabanggit . Sa polymorphism , ang
bawat subclass ay maaaring magkaroon ng sarili nitong paraan ng
pagpapatupad ng mga function. Kaya , halimbawa, kapag ang Ilipat ang
function ay tinatawag na sa isang object ng Kabayo klase, ang pagandar na maaaring tumugon sa pamamagitan ng pagpapakita trotting sa
screen. Sa kabilang banda , kapag ang parehong mga function ay
tinatawag na sa isang object ng klase Isda , swimming maaaring
maipakita sa screen. Sa kaso ng isang Bird bagay, maaari itong
lumilipad .
Bilang resulta , trims polymorphism down na ang gawain ng nag-develop
dahil maaaring siya na ngayong lumikha ng isang uri ng pangkalahatang
klase ng lahat ng mga katangian at mga pag-uugali na envisions siya
para dito. Kapag ang oras ay para sa mga developer na lumikha ng mas
tukoy na subclasses na may ilang mga natatanging katangian at mga paguugali , maaaring baguhin lamang ang nag-develop code sa tukoy na mga
bahagi kung saan mag-iba ang pag-uugali ay . Lahat ng iba pang mga
bahagi ng code na maaaring iwanang bilang ay.
Encapsulation is a way of organizing data and methods into a structure by concealing the the way the
object is implemented, i.e. preventing access to data by any means other than those specified.
Encapsulation therefore guarantees the integrity of the data contained in the object.
Inheritance is the process wherein characteristics are inherited from ancestors. Similarly, in Java,
a subclass inherits the characteristics (properties and methods) of its superclass (ancestor). For
example, a vehicle is a superclass and a car is a subclass. The car (subclass) inherits all of the
vehicles properties. The inheritance mechanism is very useful in code reuse. The following are
some limitations of Java class inheritance: A subclass cannot inherit private members of its
superclass. Constructor and initializer blocks cannot be inherited by a subclass. A subclass can
have only one superclass.
The keyword extends is used to derive a subclass from the superclass, as illustrated by the
following syntax: class Name_of_subclass extends Name_of superclass { //new fields and
methods that would define the subclass go here } If you want to derive a subclass Rectangle from
a superclass Shapes, you can do it as follows: class Rectangle extends Shapes { . }
Pagmamana ay ang proseso kung saan ang mga katangian ay minana mula sa mga ninuno.
Katulad nito, Java, isang subclass inherits ang mga katangian (mga ari-arian at mga
pamamaraan) ng kanyang superclass (ninuno). Halimbawa, ang isang sasakyan ay isang
superclass at ng kotse ay isang subclass. Ang kotse (subclass) inherits ang lahat ng mga
pagmamay-ari ng sasakyan ni. Ang mekanismo inheritance ay lubos na kapaki-pakinabang sa
code sa muling paggamit. Ang mga sumusunod ay ilang mga limitasyon ng Java class
inheritance: Ang isang subclass ay hindi maaaring magmana pribadong mga miyembro ng
superclass nito. Taga-at initializer mga bloke ay hindi maaaring minana sa pamamagitan ng
isang subclass. Ang isang subclass maaari lamang magkaroon ng isang superclass.
Ang keyword na "umaabot" ay ginagamit upang makakuha ng isang subclass mula sa superclass,
bilang isinalarawan sa pamamagitan ng mga sumusunod na syntax: klase Name_of_subclass
umaabot Name_of superclass {// bagong mga patlang at mga pamamaraan na tukuyin ang
subclass pumunta dito} Kung nais mong kunin ang isang subclass Parihaba mula sa isang
superclass Hugis, maaari mong gawin ito tulad ng sumusunod: klase Parihaba umaabot Hugis
{.... }
sang interface ay isang koleksyon ng mga abstract pamamaraan. Isang class na ipinapatupad ng
interface, at sa gayon ay inheriting ang abstract pamamaraan ng interface.
Isang interface ay hindi isang class. Nagsusulat ng isang interface ay katulad ng pagsusulat ng
klase, ngunit ang mga ito ay dalawang magkaibang konsepto. Inilalarawan ng klase ang mga
katangian at pag-uugali ng isang bagay. Isang interface ay naglalaman ng mga pag-uugali na
ipinapatupad ng isang klase.