Sie sind auf Seite 1von 8

What is Data Abstraction?

May 26, 2006 by azagappan

Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the un-wanted characteristics of that situation or object.Lets take a person as example and see how that person is abstracted in various situations A doctor sees (abstracts) the person as patient. The doctor is interested in name, height, weight, age, blood group, previous or existing diseases etc of a person An employer sees (abstracts) a person as Employee. The employer is interested in name, age, health, degree of study, work experience etc of a person. So, you see that Abstraction is the basis for software development. Its through abstraction we define the essential aspects of a system. The process of identifying the abstractions for a given system is called as Modelling (or object modelling). In the above example, the doctor may not be interested in characteristics of a person on which the employer is interested in and vice versa. Both employer and doctor will not be interested in all the characteristics of a person (like the color of dress the person wears on a particular day, the food the person takes, the relatives of the person etc). But however some elements are common to both doctor and the employer (like name, age, height etc). This common element gives way to generalization. Ie, if we eliminate enough details of an abstraction, it become so generalized that it can be applied wide in range of situations.One good example for such a generalization is a cell. A generalized cell would look like

Though the above generalized cell doesnt look like a brain cell or muscle cell, the above can still be used to represent all cell types that have this common features. In real world, there are millions of abstractions possible and many are complex in nature. The complexities of abstractions are handled by systematically classifying and generalizing the abstractions based on some pre-defined criteria. This process is known as classification. Classification builds up a hierarchy and its called as abstract hierarchy. You can see an example of an abstract hierarchy below .

So, we see that abstraction is the basis for object oriented programming. Abstraction serves as the foundation for determining the classes for a particular system (which is called object model). But be advised, there is no acid test

to decide if the abstraction for a given system is right or wrong. A "person" abstraction for a hospital information system would be different from a person abstraction for a library information system and even with hospital information system, person abstraction may be different for different projects. Once you have abstracted an object, it can be re-used. It can be modified to suit other situations. As a child you

learnt Tri-cycle. You used the experience of learning tri-cycle (handle bar control, pedaling) to learn bicycling. What actually you do to learn bicycling is that you only learn to balance the bicycle while you use the experience of tricycle to use handlebar and pedaling. The same case applies to abstraction as well. Though abstraction seems to be a simple concept, its a challenging task. The reasons are 1. 2. There are un-limited numbers of possibilities to define an abstraction for a situation. As mentioned earlier, there is no acid test to determine if the abstraction is right or wrong. You end up discussing, arguing with your counter part that yours is best and his is worst. He does the same thing However, these problems are always addressed as you gain experience (which you can gain by reading more books/articles and doing real time projects) in defining the abstraction. Abstraction by itself is a huge and an interesting concept. But, I feel that most of the people, who define classes, do it without knowing what an abstraction is. Most of the times they are right. you to enjoy. But doing your work with more knowledge (knowing what you are doing) lets

Data Abstraction
1. The major purpose of a database system is to provide users with an abstract view of the system. The system hides certain details of how data is stored and created and maintained Complexity should be hidden from database users. 2. There are several levels of abstraction: 1. Physical Level: How the data are stored. E.g. index, B-tree, hashing. Lowest level of abstraction. Complex low-level structures described in detail. 2. Conceptual Level: Next highest level of abstraction. Describes what data are stored. Describes the relationships among data. Database administrator level. 3. View Level: Highest level.

Describes part of the database for a particular group of users. Can be many different views of a database. E.g. tellers in a bank get a view of customer accounts, but not of payroll data.

Fig. 1.1 (figure 1.1 in the text) illustrates the three levels.

Figure 1.1: The three levels of data abstraction

Encapsulation is the process of binding together of Data and Code. It can also Encapsulation is the process of binding together of Data and Code. It can also

Data Encapsulation in C++


All C++ programs are composed of the following two fundamental elements:

Program statements (code): This is the part of a program that performs actions and they are called functions. Program data: The data is the information of the program which affected by the program functions. Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding. Data encapsulation is a mechanism of bundling the data, and the functions that use them and data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user. C++ supports the properties of encapsulation and data hiding through the creation of user-defined types, called classes. We already have studied that a class can contain private, protected and publicmembers. By default, all items defined in a class are private. For example: class Box { public: double getVolume(void) { return length * breadth * height; } private: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box }; The variables length, breadth, and height are private. This means that they can be accessed only by other members of the Box class, and not by any other part of your program. This is one way encapsulation is achieved.

To make parts of a class public (i.e., accessible to other parts of your program), you must declare them after the public keyword. All variables or functions defined after the public specifier are accessible by all other functions in your program. Making one class a friend of another exposes the implementation details and reduces encapsulation. The ideal is to keep as many of the details of each class hidden from all other classes as possible.

Data Encapsulation Example:


Any C++ program where you implement a class with public and private members is an example of data encapsulation and data abstraction. Consider the following example: #include <iostream> using namespace std; class Adder{ public: // constructor Adder(int i = 0) { total = i; } // interface to outside world void addNum(int number) { total += number; } // interface to outside world int getTotal() { return total; }; private: // hidden data from outside world int total; }; int main( ) { Adder a; a.addNum(10); a.addNum(20); a.addNum(30); cout << "Total " << a.getTotal() <<endl; return 0; } When the above code is compiled and executed, it produces the following result: Above class adds numbers together, and returns the sum. The public members addNum and getTotalare the interfaces to the outside world and a user needs to know them to use the class. The private member total is something that is hidden from the outside world, but is needed for the class to operate properly.

What is data inheritance?Open or Close

Using this function, you can arrange to have passwords and files passed on automatically and securely to beneficiaries among your family, partners and friends in the case of an emergency or fatality. Data inheritance is easy -to- use:
1. Store documents and passwords in the SecureSafe online safe.

2. Specify beneficiaries who are to be given access to the data if anything should happen to you. 3. Allocate your data and passwords to your beneficiaries. 4. In the event of an emergency, the DataInherit -function guarantees the safe notification of your beneficiaries and the secure transfer of your data.

Documents and passwords which have not been assigned to anyone are securely deleted during the data inheritance, just as the account holder had wished

Inheritance (C++ only)


Inheritance is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical relationships between them. Inheritance is almost like embedding an object into a class. Suppose that you declare an object x of class A in the class definition of B. As a result, class B will have access to all the public data members and member functions of class A. However, in class B, you have to access the data members and member functions of class A through object x. The following example demonstrates this: #include <iostream> using namespace std; class A { int data; public: void f(int arg) { data = arg; } int g() { return data; } }; class B { public: A x; }; int main() { B obj; obj.x.f(20); cout << obj.x.g() << endl; // cout << obj.g() << endl; } In the main function, object obj accesses function A::f() through its data member B::x with the statement obj.x.f(20). Object obj accesses A::g()in a similar manner with the statement obj.x.g(). The compiler would not allow the statement obj.g() because g() is a member function of class A, not class B. The inheritance mechanism lets you use a statement like obj.g() in the above example. In order for that statement to be legal, g() must be a member function of class B. Inheritance lets you include the names and definitions of another class's members as part of a new class. The class whose members you want to include in your new class is called a base class. Your new class is derived from the base class. The new class contains a subobject of the type of the base class. The following example is the same as the previous example except it uses the inheritance mechanism to give class B access to the members of class A: #include <iostream> using namespace std;

class A { int data; public: void f(int arg) { data = arg; } int g() { return data; } }; class B : public A { }; int main() { B obj; obj.f(20); cout << obj.g() << endl; } Class A is a base class of class B. The names and definitions of the members of class A are included in the definition of class B; class B inherits the members of class A. Class B is derived from class A. Class B contains a subobject of type A. You can also add new data members and member functions to the derived class. You can modify the implementation of existing member functions or data by overriding base class member functions or data in the newly derived class. You may derive classes from other derived classes, thereby creating another level of inheritance. The following example demonstrates this: struct A { }; struct B : A { }; struct C : B { }; Class B is a derived class of A, but is also a base class of C. The number of levels of inheritance is only limited by resources. Multiple inheritance allows you to create a derived class that inherits properties from more than one base class. Because a derived class inherits members from all its base classes, ambiguities can result. For example, if two base classes have a member with the same name, the derived class cannot implicitly differentiate between the two members. Note that, when you are using multiple inheritance, the access to names of base classes may be ambiguous. SeeMultiple inheritance (C++ only) for more detailed information. A direct base class is a base class that appears directly as a base specifier in the declaration of its derived class. An indirect base class is a base class that does not appear directly in the declaration of the derived class but is available to the derived class through one of its base classes. For a given class, all base classes that are not direct base classes are indirect base classes. The following example demonstrates direct and indirect base classes: class A { public: int x; }; class B : public A { public: int y; }; class C : public B { }; Class B is a direct base class of C. Class A is a direct base class of B. Class A is an indirect base class of C. (Class C has x and y as its data members.) Polymorphic functions are functions that can be applied to objects of more than one type. In C++, polymorphic functions are implemented in two ways:

Overloaded functions are statically bound at compile time. C++ provides virtual functions. A virtual function is a function that can be called for a number of different userdefined types that are related through derivation. Virtual functions are bound dynamically at run time. They are described in more detail in Virtual functions (C++ only).

Understanding data associations


A data association is a user-defined grouping of related groups and elements. It can consist of one or more groups along with some or all of the elements within those groups. Before creating Rules of Visibility, it is useful to first isolate different groups and elements that you deem to be related in some fashion. For example, a logical grouping of client contact information might include the groups HomeAddress, HomePhoneNumber, and WorkPhoneNumber, as well as all of their related elements. Once you isolate such groups and elements, you can create data associations, which you can then use to create Rules of Visibility.

A data association is therefore a user-defined grouping of related groups and elements. It can consist of one or more groups along with some or all of the elements within those groups. Data associations are important because they provide an organized means of creating data-level entitlements for multiple data elements that have a common link in a single Rule of Visibility. For example, instead of creating separate Rules of Visibility for the groups HomeAddress, HomePhoneNumber, and WorkPhoneNumber and all their elements, you can create one rule and use a data association to encompass all of those groups and their elements. It is important to note that there is a one-to-one relationship between groups and business objects and between elements and business object attributes. Therefore, when you associate groups or elements, you also associate the corresponding business objects and their attributes found in XML request and response transactions. When you perform tasks related to data associations in the Administration application, you are modifying the DATAASSOCIATION,ASSOCIATEDOBJECT, and ASSOCIATEDATRIB database tables.

Das könnte Ihnen auch gefallen