Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming principles and practice using C++: Chapter 14 - Bjarne Stroustrup

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

We have discussed classes in previous lectures. Here, we discuss design of classes: Library design considerations, class hierarchies (object-oriented programming), data hiding. Inviting you refer. | Chapter 14 Graph class design Bjarne Stroustrup www.stroustrup.com/Programming Abstract We have discussed classes in previous lectures Here, we discuss design of classes Library design considerations Class hierarchies (object-oriented programming) Data hiding Stroustrup/Programming Ideals Our ideal of program design is to represent the concepts of the application domain directly in code. If you understand the application domain, you understand the code, and vice versa. For example: Window – a window as presented by the operating system Line – a line as you see it on the screen Point – a coordinate point Color – as you see it on the screen Shape – what’s common for all shapes in our Graph/GUI view of the world The last example, Shape, is different from the rest in that it is a generalization. You can’t make an object that’s “just a Shape” Stroustrup/Programming Logically identical operations have the same name For every class, draw_lines() does the drawing move(dx,dy) does the | Chapter 14 Graph class design Bjarne Stroustrup www.stroustrup.com/Programming Abstract We have discussed classes in previous lectures Here, we discuss design of classes Library design considerations Class hierarchies (object-oriented programming) Data hiding Stroustrup/Programming Ideals Our ideal of program design is to represent the concepts of the application domain directly in code. If you understand the application domain, you understand the code, and vice versa. For example: Window – a window as presented by the operating system Line – a line as you see it on the screen Point – a coordinate point Color – as you see it on the screen Shape – what’s common for all shapes in our Graph/GUI view of the world The last example, Shape, is different from the rest in that it is a generalization. You can’t make an object that’s “just a Shape” Stroustrup/Programming Logically identical operations have the same name For every class, draw_lines() does the drawing move(dx,dy) does the moving s.add(x) adds some x (e.g., a point) to a shape s. For every property x of a Shape, x() gives its current value and set_x() gives it a new value e.g., Color c = s.color(); s.set_color(Color::blue); Stroustrup/Programming Logically different operations have different names Lines ln; Point p1(100,200); Point p2(200,300); ln.add(p1,p2); // add points to ln (make copies) win.attach(ln); // attach ln to window Why not win.add(ln)? add() copies information; attach() just creates a reference we can change a displayed object after attaching it, but not after adding it (100,200) (200,300) &ln ln: win: (100,200) p1: (200,300) p2: attach() add() Stroustrup/Programming Expose uniformly Data should be private Data hiding – so it will not be changed inadvertently Use private data, and pairs of public access functions to get and set the data c.set_radius(12); // set radius to 12 c.set_radius(c.radius()*2); // double the radius (fine) c.set_radius(-9); // set_radius() could check for .