# CHAPTER 01: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING
* Grading:
* Lecture: 60%
* Quiz: 10%
* Project: 10%
* Redd design pattern
* 1, 2 patterns
* presentation record
* Midterm: 10%
* Finalterm: 30%
* Lab: 40%
## I. Introduction:
### 1. History of Object Technology:
* Major object technology milestones:
* Simula: 1967
* Smalltalk: 1972
* C++: Late 1990s
* Java: 1991
* UML: 1996
* UML 2: 2004
### 2. Object-Oriented Concepts:
* Learning OO concepts is **not** accomplished by _learning a specific development method or a set of tools_ **but a way of thinking**.
* For examples:
* Many people are introduced to OO concepts via one of these development methods or tools.
* Many C programmers were first introduced to object orientation by migrating directly to C++, before they were even remotely exposed to OO concepts.
* Some software professionals were first introduced to object orientation by presentations that included object models using UML.
-- Learning a programming language is an important step, but it is much more important to learn OO concepts first.
* Functions:
* major: thêm tính năng ko tương thích tính năng cũ
* minor: thêm tính năng cho software vẫn tương thích tính năng cũ trước đây
* patch: cho biết sửa lại tính năng cũ trước đây
### 3. Problems:
-- Learning a programming language is an important step, but it is much more important to learn OO conceps first.
* Developers who claim to be C++ programmers are simply C programmers using C++ compilers.
* Learning UML before OO concepts is similar to learning how to read an electrical diagram without first knowing anything about electricity.
-- A programmer can use just enough OO features to make a program incomprehensible to OO and non-OO programmers alike.
-- Các vấn đề thường gặp:
* problem 1: sửa lại rất nhiều
* problem 2: code dài
## II. Procedural & OO Programming:
### 1. Procedural vs. OO. Programming:
#### a. Concept 1:
-- An **object** is an **entity** that contains both **data** and **behaviours**.
-- Examples: When we look at a person, we see the person as an object.
-- An object is defined byy two components:
* ***Attributes***: eye colors, age, height, weight, ...
* ***Behaviors***: walking, talking, breathing, ...
#### b. Concept 2 (Differences between OO and Procedural):
-- In **OO design**, the attributes and behaviors are contained **within a single object**, whereas in **procedural**, or structed, design the atributes and behaviors are normally **separated**.
### 2. Limitations of Procedural programming:
-- If the data changes, many functions must also be changed.
-- Programs that are based on complex function hierachies (hệ thống phân cấp thứ bậc phức tạp) are:
* dificult to understand & maintain.
* dificult to modify & extend
* easy to break
-- In procedural programming:
* Data is separated from the procedures.
* Sometimes it is global $\to$ easy to modify data that is outside your scope $\to$ this means that access to data is uncontrolled and unpredictable.
* Having no control over the data testing and debugging are much more difficult.
### 3. Why do we change to OO. programming ?
-- Objects solve these problems by combining data and behaviors into a complete package.
* Objects contain attributes and methods.
* In an object, methods are used to operate on the data.
* We can control access to members of an object (both attributes and methods).
## III. Four principles of Object Oriented (OO):
### 1. Abstraction (Tính trừu tượng):
* The essential characteristics of an entity that distinguishes it from all other kinds of entities.
* Defines a boundary relative to the perspective of the viewer.
* It is not a concrete manifestation (một biểu hiện cụ thể), denotes the ideal essence of something.
### 2. Encapsulation (Tính đóng gói):
* Hides implementation from clients $\to$ Clients depend only on interface.
### 3. Modularity (Tính mô-đun):
* Breaks up sth complex into manageable pieces.
* Helps people understand complex systems.
### 4. Hierarchy (Tính phân cấp thứ bậc):
* Elements at the same level of the hierachy should be at the same level of abstraction.
* Chú ý: level của phân cấp thứ bậc càng tăng thì tính trừu tượng (không hiện hữu hình) càng cao.
## IV. Other Issues:
### 1. Software Design:
* Resuability:
* Portable and independent components can be reused in many systems.
* Extensibility:
* Support external plug-ins
* Flexibility:
* Change will be easy when new data / features added.
* Modification are less likely to break the system.
* Localize effect of changes.
### 2. Create a system: designing process
* Divide a system in terms of components
* Divide components in terms of sub-components
* Abstraction: Hides details of components that are irrelevant to the current design phase.
* Component identification is top-down: Decompose system into smaller, simple components
* Integration is bottom-up: Combining small components
* Design is applied using a paradigm (mô hình): procedural, modular, object oriented.
***
### 3. Abstraction:
* Procedural design:
* Define set of functions to accomplish task
* Pass information from function to function
* Modules (modular design):
* Define modules, where each has data and procedures
* Each module has a public and a private section
* Works as a scoping mechanism
* Classes/Objects (object-oriented design)
* Abstract Data Types
* Divide project in set of cooperating classes
* Each class has a very specific functionality
* Classes can be used to create multiple instances of objec
***
# CHAPTER 02: CLASSES & OBJECTS
## I. What is an object ?
### 1.Concept:
-- An **object** is an **entity** with a well-defined boundary and identity that encapsulates **state** and **behavior**
* **_State_** is represented by attributes and relationships.
* **_Behavior_** is represented by operations, methods, and state machines.
-- Informally, an object represents an entity, either physical, conceptual, or software.
### 2. State of Object:
-- State is a condition or situation during the life of an object, which satisfies some condition, performs some activity, or waits for some event (chủ yếu nói về trạng thái, đặc điểm riêng biệt của một chủ thể).
-- The state of an object normally changes over time.
-- Example: Professor Clark's attributes
* Name: J.Clark
* EmployeeID: 567138
* Date Hired: July 25, 1991
* Status: Tenured (được thuê)
* Discipline: Finance
* Maximum Course Load: 3 classes
### 3. Behavior of Object:
-- Behavior determines how an object acts and reacts (chủ yếu nói về hành động của chủ thể đó).
-- the visible behavior of an object is modeled by a set of messages it can respond to (operations that the object can perform).
-- Example: Professor J.Clark's behaviors
* Submit Final Grades
* Accept Course Offering
* Set Max Load
### 4. Identity of Objects:
-- Each object has **a unique identity**, even if the state is identical to that of another object (chủ yếu nói về đặc trưng của một chủ thể nhằm phân biệt hai chủ thể).
-- Example:
* Professor "J Clark" teaches Biology
* Professor "J Clark" teaches Math.
## II. What is a class ?
### 1. Concept:
-- A **class** is a description of set of objects that share the same attributes (thuộc tính), operations, relationship, and semantics.
-- A class is an abstract definition of an object.
* It emphasizes relevant characteristics.
* It suppresses other characteristics.
* It defines the structure and behavior of each object in the class.
* It serves as a template for creating objects.
-- Class are not collections of objects.
### 2. Representing Classes in the UML:
-- A class is represented using a rectangle with three compartments:
* The **class name**
* The **attributes**
* The **operations**
-- A cass can be represented using a simple rectangle.
<center><img src=https://blogloi.com/wp-content/uploads/2015/09/xay-dung-lop-doi-tuong-trong-java-oop.png></center>
### 3. What is an Attribute / Operation ?
-- An **attribute** is a named property of a class that describes the range of values the instances of the property may hold.
-- An **operation** is the implementation of a service that can be requested from any object of the class to affect behavior. In other words, an operation is an abstraction.
-- Class declaration in C++:
* Syntax:
```cpp=
```
***
# CHAPTER 03: MORE ABOUT CLASSES
## I. Constructors:
### 1. Concept:
-- A **constructor** is a special member function that is automatically called when a class object is created.
* Remember that when we define a local variable (primary data type) in C++ the memory is not automatically initialized.
-- Characteristics of constructors:
* It is **automatically** invoked when a new project is created.
* There is **no** returned value, even a void.
* A class can have that one constructor (overload).
* Name of the constructors **must be the same as** the class name.
### 2. Declaring & Implementing a Constructor:
```cpp=
class Human
{
public:
Human()
{
// constructor code here
Name = "Le Thi Dep";
DateOfBirth = "01/01/1990";
PlaceOfBirth "Ha Noi";
Gender = "Female";
}
...
};
```
### 3. When & How to use Constructors:
```cpp=
#include <iostream>
#include <string>
using namespace std;
class Human
{
private:
// Private member data:
string name;
int age;
public:
// constructor
Human()
{
age = 0;
}
void setName(string humansName)
{
name = humansName;
}
void setAge(int humansAge)
{
age = humansAge;
}
void introduceSelf()
{
cout << "I am " + name << " and am";
cout << age << " years old" << endl;
}
};
int main()
{
Human FirstMan;
FirstMan.setName("Adams");
FirstMan.setAge(30);
Human FirstWoman;
FirstWoman.setName('Eve');
FirstWoman.setAge(28);
FirstMan.introduceSelf();
FirstWoman.introduceSelf();
return 0;
}
```
### 4. Overloading Constructors:
* **Default Constructors**: *if no constructor is implemented, the compiler will issue a default constructors; if there is at least one constructor, the default constructor will not be created by the compiler.*
* No parameters
* Invoke other default constructors of data members if they are objects.
* Doesn't initialize other data members if they are not objects.
* Constructor with no parameters
* Constructor with parameter(s)
## II. Destructors:
### 1. Concept:
-- A destructors
## III. Member Initialization:
## IV. Copy Constructors:
-- Copy constructors sẽ có 3 trường hợp được sử dụng:
* Sao chép đối tượng khi tạo một đối tượng mới dựa trên một đối tượng hiện có
* Truyền đối tượng làm tham số cho một hàm
* Trả về đối tượng từ một hàm
* Sao chép một đối tượng vào một mảng hoặc container
* Sao chép đối tượng trong trường hợp gán (assignment)
## V. Staic Members: