Object Oriented Programming Lecture 3 Things OO Jargon
Object Oriented Programming Lecture 3: Things OO
Jargon l l Class / Instance Multiple instances of a Class Data fields Methods
Class & Instance l l Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle l Used in graphics programming for size of Window or enclosing area for text or image l In creating a window Create. Window(…, 100, 300, 500, …); – Create. Window(…, top, right, width, height, …); –
Class & Instance l l Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle l Used in graphics programming for size of Window or enclosing area for text or image l In creating a window Create. Window(…, 100, 300, 500, …); – Create. Window(…, top, right, width, height, …); – – Create. Window(…, winrect, …);
Class & Instance l l Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle l Used in graphics programming for size of Window or enclosing area for text or image l In creating a window Create. Window(…, 100, 300, 500, …); – Create. Window(…, top, right, width, height, …); – Rectangle winrect; – winrect. top = 100; winrect. right = 100; …. – Create. Window(…, winrect, …); – – PAYOFF ? ? ? ?
Class & Instance l l Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle l Used in graphics programming for size of Window or enclosing area for text or image l In creating a window Create. Window(…, 100, 300, 500, …); – Create. Window(…, top, right, width, height, …); – Rectangle winrect(100, 300, 500); – Create. Window(…, winrect, …); – Create. Window(…, Rectangle(100, 300, 500), …); – – PAYOFF ? ? ? ?
Rectangle Actions l What might we want to do with rectangles? – – Specify a size and location (window, …) Eg: text area Combine, scale, centre, intersect Eg: size and centre a window, text
Rectangle Storage l How do we represent a rectangle l position and size or four corners
OO l l Group data together (struct) Encapsulate (private components) – – Implementation hiding Separate interface from implementation
OO Rectangle class Rectangle { private: int top, left, bottom, right; public: int get. Width() { return right – left + 1; } }
Demonstration l J 02 program – Shows how to use a Frame from Java AWT to open a window
- Slides: 11