Frequently, when a window displays something, that something is an object as well. Conceptually, each object is responsible for itself.
For example, a Windows ob- ject is responsible for things like opening, sizing, and closing itself. A chart object is responsible for maintaining its data and labels and even for drawing itself. Programming in an object-oriented system consists of adding new kinds of ob- jects to the system and defining how they behave. Frequently, these new object classes can be built from the objects supplied by the object-oriented system, 2.
Also, we routinely divide the world along a second dimension: We distinguish classes from instances. When an eagle flies over us, we have no trou- ble identifying it as an eagle and not an airplane. What is occurring here? Even though we might never have seen this particular bird before, we can immediately identify itas an eagle. Clearly, we have some general idea of what eagles look like, sound like, what they do, and what they are good for—a generic notion of eagles, or what we call the class eagle.
Classes are used to distinguish one type of object from another. In the context of object-oriented systems, a class is a set of objects that share a common struc ture and a. Inheritance is discussed tater in this chapter. Classes are an important mechanism for classifying objects. The chief role of a class is to define the properties and procedures the state and behavior and ap- plicability of its instances.
The class cary for example, defines the property color. Each individual car formally, each instance of the class car will have a value for this property, such as maroon, yellow, or white In. Each object is an instance of a class. Every object of a given class has the same data format and responds to the same: instructions: For exam- ple, employees, such as Sue, Bill, Al, Hal, and David all are instances of the class Employee.
You can create unlimited instances of a given class. The instructions re- sponded to by each of those instances of employee are managed by the class. The data associated with a particular object is managed by the object itself. For exam- ple, you might have two employee objects, one called Al and the other Bill. Each employee object is responsible for its own data, such as social security number, address, and salary.
In short, the objects you use in your programs are instances of classes. You can use any of the predefined classes that are part of an object-oti- ented system or you can create your own. Often, we want to refer to the descrip- tion of these properties rather than how they are represented in a particular pro- gramming language. Cost could be a floating point number, a fixed point number, or an integer in units of pennies or even lira.
The importance of this distinetion is that an object's abstract state can be independent of its physical representation 2. We can drive a car, we can ride an elephant, or the elephant can eat a peanut. In the object model, object behavior is de- scribed in methods or procedures, A method implements the behavior of an object.
Behavior denotes the collection of methods that abstractly describes what an object is capable of doing. Each procedure defines and describes a particular behavior of an object. The object, called the receiver, is that on which the method operates. Consequently, procedures provide us the means to communicate with an object and access its properties.
The use of methods to exclusively access or update proper- ties is considered good programming style, since it limits the impact of any later changes to the representation of the properties. Methods conceptually are equivalent to the function definitions used in procedural lan- guages.
For example, a draw method would tell a chart how to draw itself. How- ever, 10 do an operation, a message is sent to an object. Objects perform opera- tions in response to messages. Following a set of conventions, or protocols, protects the developer or user from unauthorized data manipulation, Messages essentially are nonspecific function calls: We would send a'draw message to a chart when we want the chart to draw itself.
A message is different from a subroutine call, since different objects can respond to the same message in different ways. For example, cars, motorcycles, and bicycles will all respond 10 a stop message, but the actual operations performed are object specific.
In the top example, depicted in Figure , we send a Brake message to the Car object. In the middle example, we send a multiplication message to 5 object fol- lowed by the number by which we want to multiply 5. In the bottom example, a Compute Payroll message is sent to the Employee object, where the employee ob- ject knows how to respond to the Payroll message. It is the receiver's responsibility to respond to a message in an appropri ate manner. This gives you a great deal of flexibility, since: different objects can respond to the same message in different ways.
Methods are similar to functions, procedures, or subroutines in more traditional programming languages, such as COBOL, Basic, or C, The area where methods and functions differ, however, is in how they are invoked. In'a Basic program, you call the subroutine e. A message is much more general than a function call.
To draw a chart, you would send a draw message to the chart object. Notice that draw is a more general instruction than, say, draw a chart. That is be- cause the draw message can be sent to many other objects, such as a line or cit cle, and each object could act differently.
Itis important to understand the difference between methods and messages. Say you want to tell someone to make you French onion soup.
In other words, the message is the instruction and the method is the implementation. An object or an instance of a class understands mes- sages. A message has a name, just Hike a method, such as cost, set cost, cooking time. An-object understands a message when it can match the message to a method that has a same name as the message.
To match up the message, an object first searches the methods defined by its class. If found, that method is called up. If not found, the object searches the superclass of its class. If it is found in a superclass, then that method is called up. Otherwise, it continues the search upward. An error occurs only if none of the superclasses contains the method.
The result is a system more re- silient to change and more reusable, both within an application and from one ap- plication to another. For example, Simula provides no protection, or information hid- 1g, for objects, meaning that an object's data, or instance variables, may be ac- cessed wherever visible. However, most object-oriented languages provide a well- defined interface to their objects through classes. Private members are accessible only from within a class.
An object data representation, such as a list or an array, usually will be private, Protected. This ensures not only that instructions are operating on the proper data but also that no object can operate directly on another object's data. Another issue is per-object or per-class protection. In per-class protection, the most common form e. In persobject protection, methods can access only the receiver. A car engine is an example of encapsulation. Although engines may differ in implementation, the interface between the driver and the car is through a common protocol: Step on the gas to increase power and let up on the gas to decrease power.
Data are abstracted when they are shielded by 4 full set of methods and only those methods can access the data portion of an object 2. The family car in Figure 5a subelass of car. A subclass inherits all of the properties and methods proce- ures defined in its superclass. In this case, we can drive a family car just as we can drive any car or, indeed, almost any motor vehicle.
Subclasses generally add new methods and properties specific to that elass. Subclasses may refine or con- strain the state and behavior inherited from its superclass. In this manner, subclasses modify the attribute number of passengers of its superclass, Car.
By contrast, superclasses generalize behavior. It follows that a more general state and behavior is modeled as one moves up the superclass-subelass hierarchy or simply class hierarchy and a mote specific state is modeled as one moves down. Tris evident from our example that the notion of subelasses and superclasses is relative, A class may simultaneously be the subclass to some class and a super- class to another class es.
Truck is a subclass of a motor vehicle and a superciass of both [8-wheeler and pickup. How- ever, the Ford class may not be the most general in our hierarchy. For instance, the Ford class is the subclass of the Car class, which is the subclass of the Vehicle class.
Object-oriented notation will be covered in Chapter 5, the chapter on object- oriented modeling. This methodology is limiting because, if you decide later to create a Ford Taurus object, you will have to duplicate most of the code that describes not only how a vehicle behaves but also how a car, and specifically a Ford, behaves.
This duplication occurs when using procedural language, since there is no concept of hierarchy and inheriting behavior. There is no such thing as a generic car, All cars must be of some make and model. In the same way, there are no instances of Ford class.
All Fords must belong to one of the subclasses: Mustang, Escort, Taurus, or Thunderbird, The Car class is a formal class, also called an abstract class.
Formal or abstract classes have no instances but define the common behaviors that can be inherited by more specific classes. In some object-oriented languages, the terms superclass and subclass are used instead of base and derived.
In this book, the terms superclass and subclass are used consistently. Inheritance is a relationship between classes where one class is the parent class of another derived class. The parent class also is known as the base class or superclass.
Inheritance provides programming by extension as opposed to programming by reinvention [10]. The real advantage of using this technique is that we can build on what we already have and, more important, reuse what we already have. Inheritance allows classes to share and reuse behaviors and attributes. Where the behavior of a class instance is defined in that class's methods, a class also inherits the behaviors and attributes of all of its superclasses, For example, the Car class defines the general behavior of cars.
The Ford class inherits the general behavior from the Car class and adds behavior specific to Fonds. It is not necessary to redefine the behavior of the car class; this is inherited. Another level down, the Mustang class inherits the behavior of cars from the Car class and the even more specific behavior of Fords from the Ford class. The Mus- tang class then adds behavior unique to Mustangs: Assume that all Fords use the same braking system.
In that case, the stop method would be defined in class Ford and not in Mustang class , since it is a be- havior shared by all objects of class Ford. The article on OOAD Notes covers all the important topics, and students must ensure that they read through all the topics and concepts before their attempt at the OOAD examination.
When students know all the topics and concepts, they will be able to answer the question paper easily and conformably. Students studying Bachelors in Technology B. Tech can access the article and read through the list of important questions in the section below for the OOAD or Object-Oriented Analysis and Design course program. All the important review questions enlisted in the section below help students excel in their examinations and secure the best grades in their examinations.
Question 1. Question 2. Question 3. Question 4. List out of the important questions that students can refer to when they are preparing for the Object-Oriented Analysis and Design examination. Answer: Here are some of the important questions that students can refer to when they are preparing for the Object-Oriented Analysis and Design examination:. The article on OOAD Lecture Notes is a credible and reliable source of reference that enlists all the important sources mentioned above aims at helping students improve and enhance their knowledge and comprehension of the subject during their preparation process.
Define an abstract class and explain its use. Would you say that a concrete class can be a superclass? If yes, explain your answer and give examples for the same, if no, explain your reason.
Which is the phase which requires the most effort? One of the stages of SDLC Is the domain analysis, under which there are many sub-divisions, explain the importance of the domain analysis and expand the sub-divisions with a suitable explanation.
Make a comparative study between the similarities and dissimilarities between a sequence diagram and a collaboration diagram. In an object diagram, show at least ten relationships between the object classes.
As a part of the object diagram, include associations and qualified associations: aggregations, generalization, and other additional objects. Prepare an interaction diagram for an ATM, which is used for a card-banking system. Answer: Here are some of the important questions that students can refer to when they are preparing for the Object-Oriented Analysis and Design examination: Define an abstract class and explain its use. Conclusion The article on OOAD Lecture Notes is a credible and reliable source of reference that enlists all the important sources mentioned above aims at helping students improve and enhance their knowledge and comprehension of the subject during their preparation process.
0コメント