This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 1 Lesson 2: Pong Class Design.

Slides:



Advertisements
Similar presentations
Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Advertisements

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.
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Chapter 1 Inheritance University Of Ha’il.
Exercises on Basic OOP TCP1201: 2013/2014. Catch the Bug 1 class Point { private : int x, y; public : Point(int u, int v) : x(u), y(v) { } int getX()
Lecture 28: Abstract Classes & Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Read: –Chapter 9 Cahoon & Davidson.
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
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,
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
Twin A Design Pattern for Modeling Multiple Inheritance Mahmoud ghorbanzadeh.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
Primitive Values Vs Objects Wrapper Classes Memory Representation of Primitive Values Vs Objects –Pointers Equal Vs == Sharing of Objects Garbage Collection.
Object-Oriented Design 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance Is a form of software reusability in which programmers create classes that absorb an existing class’s data and behaviors and enhance them with.
Computer Science I Inheritance Professor Evan Korth New York University.
AIXM Viewer Implementation Presentation to AIXM Users’ Conference, Federal Aviation Administration, Washington D.C., Feb 27-March 1, By: Mark Austin,
1 Data Structures - CSCI 102 CS102 C++ Polymorphism Prof Tejada.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
1 What is Inheritance? zThe mechanism of deriving a new class from an old one is called inheritance zClasses organised into a ‘classification hierarchy’
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
Things and Relations - Examples Things Relationships Structural Behavioral Grouping Annotational Dependency Association Generalization Realization Class,
CS 2430 Day 9. Announcements Quiz on Friday, 9/28 Prog1: see , see me as soon as possible with questions/concerns Prog2: do not add any public methods.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 23 Game Graphics II.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
Object Oriented Design. Object-Oriented Design Method for designing computer programs –Useful for thinking about large problems Consider “objects” interacting.
Description, Classes, Interfaces, Hierarchy, Specifics George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
CSSE501 Object-Oriented Development. Chapter 12: Implications of Substitution  In this chapter we will investigate some of the implications of the principle.
1 Given the Radio class  We may define other derivative types: Cassette walkman IS-A radio Alarm clock radio IS-A radio Car radio IS-A radio.
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
Exercises on Basic OOP TCP1201: 2013/2014.  Problem: Design and build a computer hockey game.  Object: Hockey player  Attribute: Position, height,
1 Computer Science 340 Software Design & Testing Inheritance.
بسم الله الرحمن الرحيم ” اللهم أنت ربي لا إله إلا أنت خلقتني و أنا عبدك وأنا على عهدك ووعدك ما استطعت ، أعوذ بك من شر ما صنعت ، أبوء لك بنعمتك على و أبوء.
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.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
Inheritance & Dynamic Binding. Class USBFlashDrive We better introduce a new class USMBFlashDrive and save() is defined as a method in that class Computer.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Session 13 Pinball Game Construction Kit (Version 3):
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
A Introduction to Computing II Lecture 4: Visual Programming A Case Study of OOP Fall Session 2000.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Polymorphism CMPS Poly-morphism Means “many-forms” Means different things in biology, chemistry, computer science Means different things to functional.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Computer Science 209 Software Development Inheritance and Composition.
29-July-2002cse Inheritance © 2002 University of Washington1 Inheritance CSE 142, Summer 2002 Computer Programming 1
Topics Inheritance introduction
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
(c) University of Washington02-1 CSC 143 Java Object and Class Relationships: Interfaces Reading: Ch. 9 (on Java interfaces)
AP Computer Science A – Healdsburg High School 1 Inheritance - What is inheritance? - “Is-a” vs. “Has-a” relationship - Programming example “CircleBug”
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
Welcome back!. Object Oriented Programming – Encapsulation Classes encapsulate state (fields) and behavior (methods) – Polymorphism Signature Polymorphism.
1 CSC241: Object Oriented Programming Lecture No 17.
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
Video Game Package Intro 1 Last Edited 1/10/04CPS4: Java for Video Games Introduction.
Lecture 2 Object-oriented programming. Definitions of OOP OOP is a programming paradigm, which utilizes encapsulation, inheritance and polymorphism. (From.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Greenfoot Workshop Bobby - Snake.
Copyright 2009 by Pearson Education Building Java Programs Chapter 9: Inheritance and Interfaces Lecture 9-1.
Week 5 Extending classes in Java. Extending classes u Using an existing classes as the basis for a new one u Defining only the differences between the.
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 1 Lesson 1: Introduction to Pong.
Modern Programming Tools And Techniques-I
Chapter 15 Abstract Classes and Interfaces
Lecture 12 Inheritance.
Chapter 9 Carrano Chapter 10 Small Java
C++ Programming CLASS This pointer Static Class Friend Class
Expanding the PinBallGame
Computer Science II for Majors
Presentation transcript:

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 1 Lesson 2: Pong Class Design

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 2 Review What classes did we identify? What behaviors does each class display?

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 3

4 Inheritance Relationships Name some features of cars What are features that all cars have? How are British cars different from American cars? How does a Mini Cooper in London differ from one in California? How is a Mini Cooper in California similar to a Ford Escort in New York?

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 5 Inheritance Classes may inherit features from other classes Similar classes may inherit features from a single parent class (e.g. “British cars” are Cars, “American cars” are Cars) This is a called an “is-a” relationship “Car” is a parent of “British car” and “American car”

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 6 Inheritance What is the difference between inheriting features from a class, and being an instance of that class?

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 7 Provided Classes for Pong Game –Is a parent for the Pong class GameObject –Is a parent for the Paddle and Ball class

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 8

9 Provided Methods Game –void add(GameObject o): Adds an object to the screen –boolean ZKeyPressed(), boolean XKeyPressed(), boolean NKeyPressed(), boolean MKeyPressed(): Tests whether or not a user is attempting to move a paddle

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 10 Provided Methods GameObject –boolean collides(GameObject o): Tests for collision with another object –int getX(), int getY(): returns the X and Y positions of an object –void setX(int x), void setY(int y): sets the X and Y positions of an object –void setSize(int width, int height): sets the size of an object

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 11 Explore What is Provided How can the provided methods help you implement the necessary behaviors of each class? Which provided methods will be used in each behavior?

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 12 Required Methods Child classes of Game must implement: –void setup() –void act() Child classes of GameObject must implement: –void act()

This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 13 Homework What relationships exist between objects? How do objects interact with each other?