01_Object Oriented Programming
Object
What’s an object
- Object = Entity
- Object may be
- Visible or
- invisible
- Object is variable in programming languages.
对象在编程语言中,以变量的形式出现。
Objects = Attributes + Services
- Data: the properies or status
- Operations: the functions
Mapping
- From the problem space to the solution one.
写程序的过程=用计算机程序描述问题+用计算机程序解决问题。
这是一种从 问题空间->解决空间 的映射
What’s object-oriented
- A way to organize
- Designs
- Implementations
- Objects, not control or data flow, are the primary focus of the design and implementation.
- To focus on things, not operations
Object Oriented Programming
这节主要讲OOP的基本理念
- Objects send and receive messages(objects do things!)
send messages
- Message are
- Composed by the sender
- Interpreted by the receiver
- Implemented by methods
- Messages
- May cause receiver to change state
- May return results
消息以函数形式传递,消息可能会改变接受者状态(也可以返回结果)
class & object
The fish is fish. The bird is bird. (Aristotle)
- Objects (cat)
- Represent things, events, or concepts
- Respond to messages at run-time
- Classes (cat class)
- Define properties of instances
- Act like types in C++
OOP Characteristics
- Everything is an object
- A program is a bunch of objects telling each other what to do by sending messages.
这里是 what to do 不是 how to do
- Each object has its own memory made up of other object.
每个对象都有由其他对象组成的自己的内存
- Every object has a type
- All objects of a particular type can receive the same messages.
interface
- The interface is the way it receives messages.
- It is defined in the class the object belong to.
functions of the interface
- Commnication
- Protection
接口保护对象内部状态
The Hidden Implementation
- Inner part of an object, data members to present its state, and the actions it takes when messages is rcvd is hidden.
- Class creators vs. Client programmers
- Keep client programmers’ hands off portions they should not touch.
- Allow the class without worrying about how it will affect the client programmers.
- Post title: 01_Object Oriented Programming
- Create time: 2022-08-05 00:22:43
- Post link: Code-like-tourist/01-object-oriented-programming/
- Copyright notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.