
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 3 - TS. Nguyễn Thành Hùng
lượt xem 1
download

Bài giảng "Kỹ thuật lập trình hệ cơ điện tử" Chương 3 - Lập trình hướng đối tượng trong C++, cung cấp cho sinh viên những kiến thức như: Giới thiệu về thế giới hướng đối tượng; Các lớp và đối tượng; Kế thừa (dẫn xuất); Đa hình; Mẫu lớp;...Mời các bạn cùng tham khảo!
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 3 - TS. Nguyễn Thành Hùng
- TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI KỸ THUẬT LẬP TRÌNH HỆ CƠ ĐIỆN TỬ Programming Engineering in Mechatronics Giảng viên: TS. Nguyễn Thành Hùng Đơn vị: Bộ môn Cơ điện tử, Viện Cơ khí Hà Nội, 2020 1
- Chapter III. Object-oriented programming in C++ ❖ Introduction to the object-oriented world ❖ Classes and objects ❖ Inheritance (derivation) ❖ Polymorphism ❖ Class templates 2
- Chapter III. Object-oriented programming in C++ ❖ Introduction to the object-oriented world ❖ Classes and objects ❖ Inheritance (derivation) ❖ Polymorphism ❖ Class templates 3
- Introduction to the object-oriented world ❖ Basics ❖ Basic principles ❖ An object-oriented example code 4
- Introduction to the object-oriented world ❖ Basics ▪ Class • A class determines the abstract features of a object, including its features (attributes, fields, properties) and its behaviour (what the thing can do, methods, operations and functions). • We can say that a class is a scheme describing the nature of something. • Both the integrated properties and the methods of a class are called class members. 5
- Introduction to the object-oriented world ❖ Basics ▪ Object • An object is a scheme (an example) of a class. ▪ Instance • Instance means an actual object created at runtime: myCar is an instance of the class Truck. • The set of the property values of the actual object is called the state of that object. 6
- Introduction to the object-oriented world ❖ Basics ▪ Method • Methods are responsible for the capabilities of objects: the methods of myCar: Brake(), Ignition(), ... • In C++, methods are rather called member functions. ▪ Message passing • Message passing is the process during which an object sends data to another object or "asks" another object to execute one of its methods. • On the code level, message passing is realised by calling a method in C++. 7
- Introduction to the object-oriented world ❖ Basics ❖ Basic principles ❖ An object-oriented example code 8
- Introduction to the object-oriented world ❖ Basic principles ▪ Encapsulation, data hiding • Classes principally consist of features (state) and methods (behaviour). • There are some features and methods that we hide from other objects. These are internal (private or protected) states and behaviour. • However, the others are made public. • According to the basic principles of OOP, the state features have to be private while most of the methods may be public. 9
- Introduction to the object-oriented world ❖ Basic principles ▪ Inheritance • Inheritance means creating specific versions of a class that inherit the features and behaviour of their parent class (base class) and use them as if they were of their own. The classes created in this way are called subclasses or derived classes. Inheritance 10
- Introduction to the object-oriented world ❖ Basic principles ▪ Inheritance • Actually, inheritance is an is-a relation: myCar is a HeavyTruck, a HeavyTruck is a Truck. So myCar has the methods of both HeavyTruck and Truck. • Both derived classes have one direct parent class, namely Truck. This inheritance method is called single inheritance. • Multiple inheritance means that a derived class inherits the members of more direct parent classes. 11
- Introduction to the object-oriented world ❖ Basic principles ▪ Inheritance Multiple inheritance 12
- Introduction to the object-oriented world ❖ Basic principles ▪ Abstraction • Abstraction simplifies complex reality by modelling problems with their corresponding classes and it has its effects on the level of inheritance appropriate for these problems. • Abstraction can be achieved through composition. • An interface determines how to send element or receive from element messages and it gives information about the interaction between the components of the class. 13
- Introduction to the object-oriented world ❖ Basic principles ▪ Abstraction 14
- Introduction to the object-oriented world ❖ Basic principles ▪ Polymorphism • Polymorphism makes it possible to replace the content of some inherited (deprecated) behaviour forms (methods) with a new one in the derived class and to treat the new, replaced methods as the members of the parent class. 15
- Introduction to the object-oriented world ❖ Basics ❖ Basic principles ❖ An object-oriented example code 16
- Introduction to the object-oriented world ❖ An object-oriented example code 17
- Chapter III. Object-oriented programming in C++ ❖ Introduction to the object-oriented world ❖ Classes and objects ❖ Inheritance (derivation) ❖ Polymorphism ❖ Class templates 18
- Classes and objects ❖A class declaration has two parts: ➢ The header of the class contains the keyword class/struct, followed by the name of the class. ➢ The class body is enclosed within curly brackets followed by a semi-colon ➔ contain the data members, member functions, and the keywords regulating access to the members and followed by a colon: public, private (hidden) and protected. 19
- Classes and objects ❖General form of a class: 20

CÓ THỂ BẠN MUỐN DOWNLOAD
-
Bài giảng Kỹ thuật thi công 1: Phần III - Đặng Xuân Trường
150 p |
360 |
134
-
Bài giảng Kỹ thuật lập trình vi điều khiển - ĐH Phạm Văn Đồng
115 p |
163 |
33
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 9 - TS. Đặng Thái Việt
34 p |
20 |
4
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 8 - TS. Đặng Thái Việt
43 p |
31 |
4
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 3 - TS. Đặng Thái Việt
48 p |
14 |
3
-
Bài giảng Kỹ thuật thi công - Trường Đại học Kỹ thuật Công nghiệp
193 p |
11 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 13 - TS. Đặng Thái Việt
83 p |
27 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 12 - TS. Đặng Thái Việt
16 p |
16 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 11 - TS. Đặng Thái Việt
22 p |
23 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 10 - TS. Đặng Thái Việt
33 p |
12 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 1 - TS. Đặng Thái Việt
33 p |
18 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 2 - TS. Đặng Thái Việt
25 p |
21 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 7 - TS. Đặng Thái Việt
31 p |
19 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 6 - TS. Đặng Thái Việt
61 p |
13 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 5 - TS. Đặng Thái Việt
35 p |
19 |
3
-
Bài giảng Kỹ thuật lập trình hệ cơ điện tử: Chương 4 - TS. Đặng Thái Việt
36 p |
10 |
3
-
Bài giảng Kỹ thuật và công nghệ thi công: Chương 8 - TS. Mã Chí Hiếu
50 p |
1 |
1
-
Bài giảng Kỹ thuật thi công (Phần 3): Chương 2 - Th.S Đỗ Thị Xuân Lan
71 p |
1 |
1


Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn
