Object Oriented Programming Lecture 3: Things OO
Jargon Class / Instance Multiple instances of a Class Data fields Methods
Class & Instance Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle Used in graphics programming for size of Window or enclosing area for text or image In creating a window – CreateWindow(…, 100, 100, 300, 500, …); – CreateWindow(…, top, right, width, height, …);
Class & Instance Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle Used in graphics programming for size of Window or enclosing area for text or image In creating a window – CreateWindow(…, 100, 100, 300, 500, …); – CreateWindow(…, top, right, width, height, …); – CreateWindow(…, winrect, …);
Class & Instance Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle Used in graphics programming for size of Window or enclosing area for text or image In creating a window – CreateWindow(…, 100, 100, 300, 500, …); – CreateWindow(…, top, right, width, height, …); – Rectangle winrect; – winrect.top = 100; winrect.right = 100; …. – CreateWindow(…, winrect, …); – PAYOFF ???????
Class & Instance Analogous to Type & Variable Example – Just for design purposes (not AWT) – Rectangle Used in graphics programming for size of Window or enclosing area for text or image In creating a window – CreateWindow(…, 100, 100, 300, 500, …); – CreateWindow(…, top, right, width, height, …); – Rectangle winrect(100, 100, 300, 500); – CreateWindow(…, winrect, …); – CreateWindow(…, Rectangle(100, 100, 300, 500), …); – PAYOFF ???????
Rectangle Actions 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 How do we represent a rectangle position and size or four corners
OO 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 getWidth() { return right – left + 1; } }
Demonstration J02 program – Shows how to use a Frame from Java AWT to open a window