Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Programming Lecture 3: Things OO.

Similar presentations


Presentation on theme: "Object Oriented Programming Lecture 3: Things OO."— Presentation transcript:

1 Object Oriented Programming Lecture 3: Things OO

2 Jargon Class / Instance Multiple instances of a Class Data fields Methods

3 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, …);

4 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, …);

5 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 ???????

6 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 ???????

7 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

8 Rectangle Storage How do we represent a rectangle position and size or four corners

9 OO Group data together (struct) Encapsulate (private components) – Implementation hiding – Separate interface from implementation

10 OO Rectangle class Rectangle { private: int top, left, bottom, right; public: int getWidth() { return right – left + 1; } }

11 Demonstration J02 program – Shows how to use a Frame from Java AWT to open a window


Download ppt "Object Oriented Programming Lecture 3: Things OO."

Similar presentations


Ads by Google