// Chapter 1 TimeStamp: 2005-3-28chapter 1. Introduction to Object-Oriented Concepts
Procedural Versus OO Programming
Moving from procedural to Object-Oriented Developments
What EXACTLY IS An Object?
What EXACTLY IS A CLASS?
Using UML TO Model A Class Diagram
ENCAPSULATION
Inheritance
POLYMORPHISM
Composition
Conclusion
Chapter 1. Introduction to Object-Oriented Concepts
Chapter 1. Object-oriented concept introduction
The boss first introduced the entire OO development process and the big situation, I was slightly. But there is such a paragraph:
Even WHEN a TREND TO Wrap The Legacy Systems In Object Wrappers.
Object Wrappers
Object Wrappers Are Object-Oriented Code That Includes Structure, You CAN Take A Structure Module and Wrap It Inside An Object To Make It Look Like An Object.
Object Wrappers is to encapsulate structured code in object-oriented code. For example, you can package a structured module in an object that makes it look like an object. (The meaning of the words is that this is not an object?! How to understand?)
In this chapter, the old man will take us to master the fundamental concept of OO.
Procedural Versus OO Programming
Process VS OO
Before we delve deeper into the advantages of OO development, let's consider a more fundamental question: What exactly is an object This is both a complex and a simple question It is complex because shifting gears to learn a totally new way of thinking is not?. .
Further, further research OO development advantages, let us first consider a question: What is an object? This is a complex and simple problem. It is said that it is complicated because it is completely changed a simple matter, saying it is simple because most people are thinking about the concept of objects.
For example, when you look at a person, you see the person as an object And an object is defined by two terms:.. Attributes and behaviors A person has attributes, such as eye color, age, height, and so on A. person also has behaviors, such as walking, talking, breathing, and so on. In its basic definition, an object is an entity that contains both data and behavior. The word both is the key difference between the more traditional programming methodology, procedural programming , and OO programming. in procedural programming, code is placed into totally distinct functions or procedures. Ideally, as shown in Figure 1.1, these procedures then become "black boxes," where inputs go in and outputs come out. Data is placed into separate For example, when you see a person, you will see someone as an object. An object is defined as two: properties and behavior.
......
An object is an entity that contains data and behavior. 'At the same time' is the key to the traditional process and OO. In the process, the code is all in a variety of significant different methods and processes. The ideal situation is like Figure 1.1, which should be a 'black box', data from the entrance, while the processed data is exported from the outlet. Data is placed in a separate structure, and these data are operated through these functions and processes.
Difference Between Oo and Procedural
This is the key difference between OO and procedural programming. In OO design, the attributes and behavior are contained within a single object, whereas in procedural, or structured design, the attributes and behavior are normally separated.
This is a key difference between the difference between OO and the process. In OO design, attributes and behaviors are placed simultaneously in a separate object. Conversely, object-oriented, separate the attributes and methods separately separately.
The second half of this section will not turn over, because it is still repeatedly deepened to explain the Data Hiding of OO, and not OO will compare confusion. Everyone knows it directly, skipping directly. Finally, the object and object directly communicating should be sent to the message, and it is also point until it will be said.
Moving from procedural to Object-Oriented Developments
Turn from the process steering object-oriented object
Procedural programing
OO Programming
We can't get it from the above two drawings:
If you need to transfer information over the network, the process-oriented process is the specific relevant data, while the object-oriented is transmitted, the specific object, including attributes, and methods.
A good example of this concept is a Web object, such as a Java applet. The browser has no idea of what the Web object will do. When the object is loaded, the browser executes the code within the object and uses the data contained within The object. A good example is Java Applet. The browser does not care about the web object itself. When those objects are loaded, the browser performs the method of the object yourself.
The old picture is still very intuitive, very good. This is worth learning a lot of comrades. This JJHO is also very good. But, too many books are full of words, just being guilty. There is a picture of the mood.
What EXACTLY IS An Object?
The boss said is also the old set, attributes and methods, and there is nothing special.
What EXACTLY IS A CLASS?
In short, a class is a blueprint for an object. When you instantiate an object, you use a class as the basis for how the object is built. In fact, trying to explain classes and objects is really a chicken-and-egg dilemma . It is difficult to describe a class without using the term object, and to describe an object without using the term class. For example, a specific bike is an object. However, someone had to have the blueprints (that is, the class) to build the bike. in OO software, unlike the chicken-and-egg dilemma, we do know what comes first-the class. An object can not be instantiated without a class. Thus, many of the concepts in this section are similar to those Presented Earlier In The Chapter, especially..
Classes Are Object Templates
.
Messages
Mussage needs to know that SmallTalk is like this, and everyone is probably more familiar with C / Java, which is less in contact with SmallTalk. Have the opportunity to learn, or it is very helpful to Think IO.
Messages are the communication mechanism between objects. For example, when Object A invokes a method of Object B, Object A is sending a message to Object B. Object B's response is defined by its return value. Only the public methods, not the private methods Of an Object Can Be Invoked by Another Object. The Following Code Illustrates This Concept: Message is the mechanism of inter-object communication. For example, when an object A calls a method of object B, we think that the object A sent a message to the object B. Object B is to make a corresponding return value for this message and return the corresponding return value. Only the PUBLIC method in the object can be called by other objects. Here is an example to explain this concept:
Public class payroll {
String name;
Person P = New Person ();
String = p.setname ("joe");
... CODE
String = p.getname ();
}
In this Example (Assuming That a payroll object is instantiated), The Payroll Object is sending a message to a person object, with the purpose of retrieving the name via the getname method.
In this example (assuming a Payroll object is instantiated), this Payroll sends a message to the Person object in order to obtain the NAME.
In fact, this is this, it is usually used in this way, but the difference in the statement indicates that everyone's way of thinking may have access, or starting from now on, using the message.
Using UML TO Model A Class Diagram
Boss is very simple, there will be a separate chapter in the back, I have urgent.
ENCAPSULATION
Encapsulate
Hiding as much data as possible This truth understands? Not much to say.
A real-world example of the interface / importation paradigm
Old big, we will look at it.
Figure 1.12 illustrates the interface / implementation paradigm using real-world objects rather than code. The toaster obviously requires electricity. To get this electricity, the cord from the toaster must be plugged into the electrical outlet, which is the interface. All the toaster needs to do to get the required electricity is to use a cord that complies with the electrical outlet specifications;. this is the interface between the toaster and the electricity The fact that the actual implementation is a coal-powered electric plant is not the concern of the toaster. in fact, for all the toaster cares, the implementation could be a nuclear power plant or a local power generator. With this model, any appliance can get electricity, as long as it conforms to the interface specification as seen in Figure 1.12. Inheritance
inherit
The boss explains the inheritance through a Dog, Cat and Mammal (mammal). This is no problem.
Inheritance is the IS-A relationship, this is known.
POLYMORPHISM
Polymorphism
This will explain the polymorphism with Sharp in C / Java, which is almost like this, I have passed.
Composition
combination
IT is Natural to Think of Objects as containing Other Objects.
In this Way, Objects Are Off Other Objects-this is Composition.
Has-a rellationships
Although an inheritance relationship is considered an is-a relationship for reasons already discussed, a composition relationship is termed a has-a relationship. Using the example in the previous section, a television has-a tuner and has-a video display. A television Is Obviously NOT A TUNER, SO THERE INHERITANCE RELATIONSHIP. IN The Same VEIN, A Computer Has-a Video Card, Has-a Keyboard, And Has-a disk drive. The topics of inheritance, composition, and how the relate to Each Other Is Covered in Great Detail in Chapter 7, "Mastering Inheritance and Composition."
The combination is the relationship between HAS-A.
Conclusion Summary There is a lot to cover when discussing OO technologies However, you should leave this chapter with a good understanding of the following topics:. Encapsulation:. Encapsulating the data and behavior into a single object is of primary importance in OO development A single object contains both its data and behaviors and can hide what it wants from other objects Inheritance:. A class can inherit from another class and take advantage of the attributes and methods defined by the superclass Polymorphism:. Polymorphism means that similar objects can respond to the same message in different manners. for example, you might have a system with many shapes. However, a circle, a square, and a star are each drawn differently. Using polymorphism, you can send each of these shapes the same message (for example , And Each Shape Is Responsible for Drawing Itself. Composition: Composition Means That An Object IS Built from Other Objects. This Chapter Covers The Fundamental Oo Concepts. By Now What OO Concepts Are All About. With this chapter, we should have a better understanding of the packages, inherit, polymorphism, and combination. If you still compare the above questions due to my translation or style, you can leave a message, ask for your opinion, I will help you solve the problem as much as possible, and make progress together.