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 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 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 (x) adds some x (., 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 ., Color c = (); (Color::blue); Stroustrup/Programming Logically different operations have different names Lines ln; Point p1(100,200); Point p2(200,300); (p1,p2); // add points to ln (make copies) (ln); // attach ln to window Why not (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 (12); // set radius to 12 (()*2); // double the radius (fine) (-9); // set_radius() could check for .