Download presentation
Presentation is loading. Please wait.
Published byMervyn Wilson Modified over 8 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.