19.2. Object-oriented Concepts

Before discussing object-oriented XML schemas, we must first define “object-oriented.” Object-oriented means “dealing with objects,” which in software development means solving problems by using software constructs to model real-world objects. This approach provides several advantages. First, software that models the real world is easier to understand. Creating an object that represents an employee within a system and then manipulating that Employee object and its properties, simplifies development because it is intuitive. People know what an employee is. Second, objects provide a unit of reuse for software. An object can be used as a “black box” that developers can take advantage of without needing to know the details of its implementation.

The advantages of object-oriented software development are best realized, of course, through the use of object-oriented languages. Like politics and religion, discussions of what makes an object-oriented language are best avoided among friends. At the heart of object-oriented languages, however, three key concepts are implemented to varying degrees. Those concepts are encapsulation, inheritance, and polymorphism.

19.2.1. Encapsulation

Encapsulation is the hiding of detail about the internal structure of an object from the users of that object. For example, a calculator provides an interface through which mathematical calculations can be performed. How those calculations occur is irrelevant, and the user of the calculator would probably prefer not to know the details of the implementation. The buttons and screen interface of the calculator encapsulate the functionality and data of the calculator. Similarly, an object in software that performs calculations encapsulates the logic involved behind the public methods of that class.

19.2.2. Inheritance

In object-oriented languages, inheritance is a method of describing common characteristics of classes by using a single class. That class is considered the base, and all classes built from that base are said to have inherited or to be derived (or subclassed) from that base. By inheriting from a base class, a new class gains the characteristics of that base class in addition to any of its own. For example, consider a base class called “Vehicle” that has properties and methods to represent characteristics common to all vehicles: maximum speed, number of occupants, fuel type, and so on. Any class that represents a specific form of vehicle, such as a train, can then derive from the Vehicle base class and inherit all those properties and methods.

19.2.3. Polymorphism

Polymorphism is similar to inheritance and builds on that concept. If two objects share a base type that expresses some common functionality, those two objects can be represented by using the base without a need to know their derived type. Inheritance is a common method of implementing polymorphism. In our previous example, both a car and a helicopter are vehicles. Although they have many different properties (altitude hopefully being one), they share the characteristics common to all vehicles. Both a car and a helicopter would be polymorphic through the vehicle base class, and one can examine either a car or a helicopter for fuel capacity, for example.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.171.121