
- •Професійна іноземна мова
- •7.05070201«Програмне забЕзПечення автоматизованих систем»
- •Професійна іноземна мова
- •7.05070201 «Програмне забЕзПечення автоматизованих систем»
- •Передмова
- •Lesson 1
- •Lesson 2
- •Lesson 3
- •Lesson 4
- •Lesson 5
- •Lesson 6
- •Lesson 7
- •Lesson 8
- •Lesson 9
- •Lesson 10
- •Lesson 11
- •Lesson 12
- •Lesson 13
- •Lesson 14
- •Lesson 15
- •Список літератури (джерел):
Lesson 7
Read the text: Object-oriented programming. Part 2.
The instance variable names can be identical to the method names that associate with them. For example, the Student object has methods of name, address, and major as well as instance variables of name, address, and major. Smalltalk distinguishes variable identifier and a method identifier by the identifier's position in the expression.
Another benefit of separating implementation from behavior is polymorphism. Polymorphism allows two or more objects respond to the same message. A method called name could also be implemented for an object of the class Course. Even though the implementation of this name message may return a course number and a course title, its protocol is the same as the name message to the Student object. Polymorphism allows a sending object to communicate with different objects in a consistent manner without worrying about how many different implementations of a message.
An analogy of polymorphism to daily life is how students respond to a school bell. Every student knows the significant of the bell. When the bell (message) rings, however, it has its own meaning to different students (objects). Some students go home, some go to the library, and some go to other classes. Every student responds to the bell, but how they response to it might be different.
Another example of polymorphism is the function of printing. Every printable object must know how to print itself. The message is the same to all the different objects: print, but the actual implementation of what they must do to print themselves varies.
The sending object does not have to know how the receiving object implement the message. Only the receiving objects worries about that. Assume that there is a printPage method in a Document object that has the responsibility of printing a page. To print the page, the printPage method sends the print message to each object on the page. The Document does not need to know what types of objects are on the page, only that each object supports the behavior of printing.
New objects can be added to the page without affecting the printPage method. This method still sends the print message and the new object provides its own print method in response to that message.
Polymorphism allows the sending object to communicate with receiving objects without having to understand what type of object it is, as long as the receiving objects support the messages.
One of the most important features of object-oriented programming is the ability to modify existing solution to solve new problems. If a particular kind of problem has been solved using the OOP approach, a similar but slightly different problem can usually be solved by making some changes in the object-message protocol that already exist. Most of the time, this requires adding new messages. Other cases may require adding new objects and new messages to which those objects respond.
Reusability is probably the most important and the strongest feature of Smalltalk. Although procedural languages can be reused too, Smalltalk makes programming for reuse much easier.
Exercise 1. Learn the following words and word-combinations:
as well as, behavior, provide, response, respond, as long as, approach |
Exercise 2. Answer the questions:
1) What is polymorphism?
2) What is an analogy of polymorphism to daily life?
3) What does polymorphism allow?
4) What is one of the most important features of object-oriented programming?
5) What is an example of polymorphism?
Exercise 3. Ask questions to the given answers:
1) Question: ________________________
Answer: : Procedural languages can be reused too.
2) Question: ________________________
Answer: Most of the time, this requires adding new messages.
3) Question: _______________________
Answer: New objects can be added to the page.
4) Question: ________________________
Answer: Every student knows the significance of the bell.
5) Question: _________________________
Answer: On average the CPU does not achieve a six-fold increase in performance.
Exercise 4. Match the left column with the right:
a) Message |
1) A feature of programming language that allows to use variables of different types at different times. |
b) Polymorphism |
2) An ability of a segment of source code to be used again to add new functionalities with slight or no modification. |
c) Reusability |
3) A verbal, written or recoded, communication sent to or left for a recipient. |
Exercise 5. Compose a story on one of the topics (up to 100 words):
1) Speak on polymorphism.
2) Some important features of object-oriented programming.