
Kỹthuật lập trình
0101010101010101100001
0101010101010101100001
0101010101010101100001
0101010100101010100101
0101010100101010100101
0101010100101010100101
1010011000110010010010
1010011000110010010010
1010011000110010010010
1100101100100010000010
1100101100100010000010
1100101100100010000010
0101010101010101100001
0101010101010101100001
0101010101010101100001
0101010100101010100101
0101010100101010100101
0101010100101010100101
1010011000110010010010
1010011000110010010010
1010011000110010010010
1100101100100010000010
1100101100100010000010
1100101100100010000010
0101010101010101100001
0101010101010101100001
0101010101010101100001
0101010100101010100101
0101010100101010100101
0101010100101010100101
1010011000110010010010
1010011000110010010010
1010011000110010010010
1100101100100010000010
1100101100100010000010
1100101100100010000010
8/13/2007
y = A*x + B*u;
x = C*x + d*u;
StateController
start()
stop()
LQGController
start()
stop()
Chương 8: Tiếntớitưduy lậptrình
hướng ₫ốitượng

2
Chương 8: Tiếntớitưduy hướng đốitượng
Nộidung chương 8
8.1 Đặtvấn₫ề
8.2 Giớithiệuvídụchương trình mô phỏng
8.3 Tưduy "rất" cổ₫iển
8.4 Tưduy hướng hàm
8.5 Tưduy dựatrên₫ốitượng (object-based)
8.6 Tưduy thựcsựhướng ₫ốitượng

3
Chương 8: Tiếntớitưduy hướng đốitượng
8.1 Đặtvấn₫ề
„Designing object-oriented software is hard, and designing reusable
object-oriented software is even harder...It takes a long time for
novices to learn what object-oriented design is all about. Exprienced
designers evidently know something inexperienced ones don't...
One thing expert designers know
not
to do is solve every problem from
first principles. Rather, they reuse solutions that have worked for
them in the past. When they find a good solution, they use it again
and again. Such experience is part of what makes them experts.
Consequently, you'll find recurring patterns of classes and
communicating objects in many object-oriented systems. These
patterns solve specific design problems and make object-oriented
design more flexible, elegant, and ultimately reusable...“
Erich Gamma et. al.:
Design Patterns: Elements of Reusable Object-
Oriented Software
, Addison-Wesley, 1995.

4
Chương 8: Tiếntớitưduy hướng đốitượng
8.2 Phầnmềmmôphỏng kiểuFBD
StaticGain Limiter Integrator
Sum Scope
1(t)
Nhiệmvụ:
Xây dựng phầnmềm₫ể hỗtrợmô phỏng thờigianthựcmột
cách linh hoạt, mềmdẻo, ₫áp ứng ₫ượccácyêucầucủatừng
bài toán cụthể
Trướcmắtchưacầnhỗtrợtạoứng dụng kiểukéothảbằng
công cụ₫ồhọa

5
Chương 8: Tiếntớitưduy hướng đốitượng
8.3 Tưduy rấtcổ₫iển
// SimProg1.cpp
#include <iostream.h>
#include <conio.h>
#include <windows.h>
void main() {
double K =1,I=0, Ti = 5;
double Hi = 10, Lo = -10;
double Ts = 0.5;
double r =1, y=0, e, u, ub;
cout << "u\ty";
while (!kbhit()) {
e = r-y; // Sum block
u = K*e; // Static Gain
ub = max(min(u,Hi),Lo); // Limiter
I += ub*Ts/Ti; // Integrator state
y = I; // Integrator output
cout << '\n' << u << '\t' << y;
cout.flush();
Sleep(long(Ts*1000));
}
}

