Kode Iklan DFP Data Abstraction | Data Structures
Kode Iklan 400x460
Kode iklan In feed above/responsive

Data Abstraction

Kode Iklan 336x280
Kode Iklan In Artikel
HPK taruh disini
A user of a class concentrates on the class’s method specifications, that is, what a class provides. A developer of a class, on the other hand, focuses on the class’s fields and method definitions, that is, how the class is defined. This separation—called data abstraction —of what from how is an essential feature of object-oriented programming. For example, programmers who use the String class will not care about the fields that represent a string or how the methods are defined. Such details would be of no help when you are trying to develop a class that uses the String class, but were essential to the developers of the String class.


In general, suppose you are a programmer who is developing class A , and during development, you decide that you will need the services of class B. If someone else has already completed the definition of class B , you should simply use that class rather than re-inventing the wheel. But even if you must define the class, B yourself, you can simply create the method specifications for class B and postpone any further work on class B until after you have completed the development of class A . By working with class B ‘s method specifications, you increase the independence of class A : its effectiveness will not be affected by any changes to class B that do not affect the method specifications of class B .

When users focus on what a class provides to users rather than on the implementation details of that class, they are applying the Principle of Data Abstraction: A user’s code should not access the implementation details of the class used.

One important application of the Principle of Data Abstraction is that if class A simply uses class B , then class A ’s methods should not access class B ’s fields. In fact, class B ’s fields should be accessed only in class B ’s method definitions. This turns out to be a benefit to users of class B because they will be unaffected if the developer of class B decides to replace the old fields with new ones. For example, suppose the following definition is made outside of the String class:
        String name;
Currently, one of the fields in the String class is an int field named count . But an expression such as 
        name.count
would be a violation of the Principle of Data Abstraction because whether or not the String class has a count field is an implementation detail. The developer of the String class is free to make any changes to the String class that do not affect the method specifications.
Most programming languages, including Java, have features that enable a developer of a class to force users to adhere to the Principle of Data Abstraction. These enforcement features are collectively known as “information hiding.”
Kode Iklan 300x250
close
==[ Klik disini 2X ] [ Close ]==
Kode Iklan DFP2
Kode Iklan DFP2