OOP-1
02 What is Object-Oriented
Objects=Attributes+Services
Data
properties or status
Operations
functions
Comparision: C && C++
1 |
|
1 |
|
What is object-oriented
A way to organize Designs and Implementations
To focus on things, not operations.
03 Fundamental of OOP
Objects send and receive messages
Messages are:
-Composed by the sender
-Interperted by the receiver(重点:让接收者自己决定执行什么动作,不接触类的data)
-Implemented by the methods
Object vs. Class
OOP Characteristics
- Everything is an object.
- A program is a brunch of objects telling each other what to do by sending messages.(WHAT, not HOW!)
- Each object has its own memory made up of other objects.
- Every object has a type.
- All objects of a particular type can receive the same messages.(反过来也成立,即可以接受相同消息的对象属于相同类型)
Functions of the Interface
-communication
-protection
OOP程序设计中希望实现松耦合
Encapsulation(封装)
Bundle data and methods dealing with these data together in an object.
Hide the details of the data and the actions.
Restrict only access to the publicized methods.
04 Example: Ticket Machine
[规范]
project: 使用全小写字母,如 ticketmachine
class: 首字母大写,如 TicketMachine
一些说明
每个类都应当包含.h和.cpp两个文件
.h中声明,.cpp中定义
:: 称为域解析符
OOP-1
http://example.com/2022/02/20/OOP-1/