“OOP” Principles and Philosophy Classes and Objects Inheritance Message Passing Encapsulation Overloading Polymorphism.

Slides:



Advertisements
Similar presentations
Rectangles moving and responding to the mouse. We want a window with a pile of rectangles in it When we click a rectangle it changes from filled to unfilled.
Advertisements

Object Oriented Programming with Java
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Web Design & Development Lecture 19. Java Graphics 2.
Polymorphism Method overriding Method overloading Dynamic binding 1.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Bar Graph Design. Left-side/Right-side mechanical processing creative, abstract reasoning.
Draw Shapes Introduction to simple graphics. What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics.
OOP: Inheritance By: Lamiaa Said.
More about classes and objects Classes in Visual Basic.NET.
TA: Nouf Al-Harbi NoufNaief.net :::
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
© A+ Computer Science - Chicken yeller = new Chicken();
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
Structured Programming Good for programming in the small Often doesn't scale up Limitations –Changes at top may affect lower-level algorithms –Code reuse.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Creating Your Own Widgets CompSci 230 S Software Construction.
Information System Design (IT60105) Lecture 26 Object-Oriented System Testing.
Drawing With Lines and Shapes!
1 Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called the parent class, or.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Session 18 Lab 9 Re-cap, Chapter 12: Polymorphism & Using Sound in Java Applications.
“Swing” - Constructing GUIs JButton JTextField. Layout Managers CENTERWEST CENTER BORDERLAYOUT this.setLayout(new BorderLayout()); this.add(displayCanvas,
COMP Object Oriented Descriptions Human Body Components Heart Actions Walking Remaining Alive Actions Components pumping Class Human Body Attributes.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Welcome back!. Object Oriented Programming – Encapsulation Classes encapsulate state (fields) and behavior (methods) – Polymorphism Signature Polymorphism.
Java exercise review Lesson 26: Exercise 4. Exercise #4 – a sample solution 1.Write the psudocode and the deployment diagram for what you are planning.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
VG101 RECITATION 5 By TAs. CONTENTS How to read Vg101Class.h Samples about graphics About assignment 5 Array.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Unified Modeling Language
12 Graphics and Java 2D™.
Creating Your Own Widgets
Inheritance ITI1121 Nour El Kadri.
Advanced Programming in Java
Object-Orientated Programming
Introduction to Object-oriented Program Design
ניתוח מערכות מידע א' הרצאה 3
A+ Computer Science METHODS.
Software Design Lecture : 12.
Web Service.
A+ Computer Science METHODS.
An Example of Inheritance
Presentation transcript:

“OOP” Principles and Philosophy Classes and Objects Inheritance Message Passing Encapsulation Overloading Polymorphism

Classes and Objects class ComplexShape class SimpleShape ACTIVITY 1

Inheritance public class ComplexShape extends SimpleShape { } ACTIVITY 1

“ Calling Methods” = “Message Passing” public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setColor(COLOR_BACKGROUND); g2.fillRect(0,0,width,height); for(i=0; i < shapesArray.length;i++) { shapesArray[i].draw(g); } public void draw(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setPaint(color); g2.setStroke(new BasicStroke(2)); if(type == 1) g2.draw(myShape); if(type == 2) g2.fill(myShape); } DisplayCanvas object SimpleShape object “Hey SimpleShape object – draw yourself!”

Encapsulation Iterator it = shapeList.iterator(); while(it.hasNext()) { SimpleShape shape = (SimpleShape)it.next(); shapeX = shape.getX(); shapeY = shape.getY();... } Private double x,y; public double getX() { return x; } DisplayCanvas object SimpleShape object shapeX = shape.x; Public double x; ACTIVITY 2

Overloading of methods public voiddraw(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setStroke(new BasicStroke(2)); if(type == 1) g2.draw(myShape); if(type == 2) g2.fill(myShape); } public voiddraw(Graphics g) { Graphics2D g2 = (Graphics2D)g; super.draw(g); g2.setStroke(new BasicStroke(10)); g2.setPaint(color2); g2.draw(newBit); } ACTIVITY 1

Polymorphism ACTIVITY 4 public Ball(double x, double y, DrawCanvas canvas) { super(x,y,canvas); radius = 10; width = (2*radius); height = (2*radius); super.setWidth(width); … } public Ball(double x, double y, String imageName, DrawCanvas canvas) { super(x,y,canvas); image = loadImage(imageName); } Class Ball Constructor 1 Constructor 2 Ball ball1 = new Ball(10,20,canvas); Ball ball2 = new Ball(12,32,”Bush.jpg”,canvas)

Modelling (Carvaggio In Study)

UML Software Tools Microsoft Visio DirectUML (Module Web-page) Fujaba Jude …

Dependency ACTIVITY 1 Task 1 UML Objects myShape = new SimpleShape(200,200,100,100,0.6); Class Object

Dependency UML Object Diagram ACTIVITY 1 Task 1

UML Class Diagram ACTIVITY 1 Task 1 Inheritance

UML Sequence Diagram Time