Object-Oriented Programming. Object-oriented programming  First goal: Define and describe the objects of the world  Noun-oriented  Focus on the domain.

Slides:



Advertisements
Similar presentations
INTRODUCTION TO ADOBE FLASH CS4
Advertisements

Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Monkey See, Monkey Do. Important Turn on Java-like syntax option in Alice, if is not on already.
CMPS 1371 Introduction to Computing for Engineers
Cosc 1P02 Week 2 Lecture slides
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Lecture 2. Review To play with Turtle, we need to download and install followings: 1.JDK 6 2.Dr. Java 3.Sample program (e.g. BookClass)
Alice: A Free 3D Animation World for Teaching Programming Barbara Ericson Georgia Institute of Technology Oct 2005.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
LEGO Mindstorms NXT Programming We will be using the Common Palette for our Robots This is how you download your program onto the brick Drag and drop a.
What is Scratch? Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Creating a MagicInfo Pro Screen Template
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Tutorial for Arrays and Lists By Ruthie Tucker. Description This presentation will cover the basics of using Arrays and Lists in an Alice world This presentation.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
BIM211 – Visual Programming Objects, Collections, and Events 1.
AP Computer Science Principles Data Abstraction and Procedural Abstraction Curriculum Module.
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
© 2012 Adobe Systems Incorporated. All Rights Reserved. Copyright 2012 Adobe Systems Incorporated. All rights reserved. ® INTRODUCTION TO FLASH ANIMATION.
® Copyright 2010 Adobe Systems Incorporated. All rights reserved. ® ® 1 INTRODUCTION TO ADOBE FLASH PROFESSIONAL CS5.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Recursion, Complexity, and Sorting By Andrew Zeng.
Microsoft® Small Basic
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Agent P, I have been hearing some rumours about a Python Turtle.
Hello, little turtles. Hello, little turtles! There are many modules in Python that provide very powerful feature that we can use in our own program.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Introduction to Scratch Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
BIL528 – Bilgisayar Programlama II Introduction 1.
How to link the robot and the computer (Bluetooth) How to turn on and off How to connect the adaptor Fluke card connection Sec Getting Started How.
Game Maker Terminology
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Georgia Institute of Technology Simulations Barb Ericson Jan 2005.
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
1 Layer up to keep warm… A short tutorial on the usage of layers.
Alice: A Free 3D Animation World for Teaching Programming.
When the program is first started a wizard will start to setup your Lemming App. Enter your company name and owner in the fields designated “Company Name”
06-Intro-Object-Oriented-Prog1 Barb Ericson Georgia Institute of Technology July 2009 Introduction to Object-Oriented Programming in Python.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Graphics CIS 40 – Introduction to Programming in Python
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
What you asked me to teach…
Flash Interface, Commands and Functions
A Tiny Look at the Graphics Window
Agent P, I have been hearing some rumours about a Python Turtle.
Introduction to.
Microsoft® Small Basic
البرمجة مع لغة PYTHON TURTLE
Overview of OOP Terminology
Introduction to Object-Oriented Programming in Alice
A Tiny Look at the Graphics Window
Presentation transcript:

Object-Oriented Programming

Object-oriented programming  First goal: Define and describe the objects of the world  Noun-oriented  Focus on the domain of the program  The object-oriented analyst asks herself: “The program I’m trying to write relates to the real world in some way. What are the things in the real world that this program relates to?”  Example: Imagine you’re building an O-O Banner  What are the objects?  Students, transcripts, classes, catalog, major-requirements, grades, rooms…

Objects  Objects as models of real world entities  Objects as Cells  Independent, indivisible, interacting—in standard ways  Scales well  Complexity: Distributed responsibility  Robustness: Independent  Supporting growth: Same mechanism everywhere  Reuse: Provide services, just like in real world

Defining an object  Objects know things.  Data that is internal to the object.  We often call those instance variables.  Objects can do things.  Behavior that is internal to the object.  We call functions that are specific to an object methods.  But you knew that one already.  We access both of these using dot notation  object.variable  object.method()

Classes  Objects are instances of classes in many object-oriented languages.  Including Smalltalk, Java, JavaScript, and Python.  A class defines the data and behavior of an object.  A class defines what all instances of that class know and can do.

Example to motivate objects: SlideShow  Let’s build a program to show a slide show.  It shows a picture.  Then plays a corresponding sound.  We’ll use the introduced-but-never-used blockingPlay() to make the execution wait until the sound is done.

Slideshow def playslideshow(): pic = makePicture(getMediaPath("barbara.jpg")) snd = makeSound(getMediaPath("bassoon-c4.wav")) show(pic) blockingPlay(snd) pic = makePicture(getMediaPath("beach.jpg")) snd = makeSound(getMediaPath("bassoon-e4.wav")) show(pic) blockingPlay(snd) pic = makePicture(getMediaPath("santa.jpg")) snd = makeSound(getMediaPath("bassoon-g4.wav")) show(pic) blockingPlay(snd) pic = makePicture(getMediaPath("jungle2.jpg")) snd = makeSound(getMediaPath("bassoon-c4.wav")) show(pic) blockingPlay(snd)

What’s wrong with this?  From Procedural Abstraction:  We have duplicated code.  We should get rid of it.  From Object-Oriented Programming:  We have an object: A slide.

The Slide Object  What does a slide know?  It has a picture.  It has a sound  What can a slide do?  Show itself.  Show its picture.  (Blocking) Play its sound.

We’ve been doing this already, of course.  You’ve been using objects already, everywhere.  Pictures, sounds, samples, colors—these are all objects.  We’ve been doing aggregation.  We’ve worked with or talked about lists of pictures, sounds, pixels, and samples  The functions that we’ve been providing merely cover up the underlying objects.

Using picture as an object >>> pic=makePicture(getMediaPath("barbara.jpg")) >>> pic.show()

What are Turtles?  Turtles are objects.  In JES, a turtle is represented as a small image of a turtle composed of a shell and a body.

What are Worlds?  Worlds are where turtles are displayed.  Worlds have height and width similar to images.  One world can hold multiple turtles.  A world = window where the turtle is

Making Turtles and Worlds  To make a turtle you must make a world first.  Make a world using the makeWorld(width, height) function ex. world = makeWorld(200, 200)  Once you have a world use the makeTurtle(world) function ex. turtle = makeTurtle(world)

Start with a world(s)  makeWorld() will create a default sized window 640 x 480 pixels  makeWorld(width, height) can be used to get the size window that you want  give your window a name: world = makeWorld(200, 300) or moshPit = makeWorld(400, 400)  You can actually have more than one window being active! footballField = makeWorld(360, 160) danceFloor = makeWorld(200, 200) quarterback = makeTurtle(footballField) fullback = makeTurtle(footballField) dancer1 = makeTurtle(danceFloor) dancer2 = makeTurtle(danceFloor)

What Can You Do With Turtles?  Once you have a turtle you can tell it to do things or change its appearance by using methods.  Methods require dot notation similar to modules. Here is an example of using methods to turn and move a turtle.

Moving Turtles  Methods for moving turtles:  forward(), moves a turtle forward by 100 pixels.  forward(x), moves a turtle forward by x pixels  backward(), moves a turtle backward 100 pixels.  backward(x), moves a turtle backward by x pixels.  moveTo(x, y), moves a turtle to the x and y position in the world.

Turning Turtles  Methods for turning/rotating turtles:  turnRight(), rotates a turtle 90 degrees to the right.  turnLeft(), rotates a turtle 90 degrees to the left.  turn(d), rotates a turtle by d number of degrees to the right. A negative number will rotate the turtle to the left.  turnToFace(turtle), rotates a turtle face another turtle.  turnToFace(x,y), rotates a turtle to an x and y position on the world.

Modifying Turtles  Methods for changing the appearance of turtles:  setColor(c), changes a turtle's shell and body color to color c.  setShellColor(c), changes a turtle's shell color to color c.  setBodyColor(c), changes a turtle's body color to color c.  setWidth(width), changes the width of a turtle.  setHeight(height), changes the height of a turtle.

Turtle Visibility  If you do not want to see a turtle anymore you can hide it.  Methods for changes the visibility settings of turtles:  hide(), stops displaying a turtle on the world. (Just makes it invisible – it is still there.)  show(), begins displaying a turtle on the world if that turtle is hidden.

The Pen  Turtles normally leave a trail when they move. You can control aspects of turtle's trail. Methods to control a turtle's pen:  penUp(), tells a turtle to stop making a trail.  penDown(), tells a turtle to begin making a trail.  setPenColor(c), changes a turtle's trail color to color c.  setPenWidth(w), changes a turtle's trail width to w.

Dropping Images  Turtles can drop images onto the world. This can be useful if you your want your world to have a background image.  First you will have to make an image using the makePicture(file) function. ex. image = makePicture(“fluffy.jpg”)  Then use the method drop(image) to drop the image onto the world.  The top left corner of the image will be the location of the turtle.

Turtle Choreography  A simple way to create an animation using turtles is by using for loops and the time module.  First import the time module: ex. import time  Create a for loop that tells a turtle to repeat an action, and end the for loop with a time.sleep() function.  time.sleep(s), creates a delay s seconds long before continuing.

See list of commands See commands from JES. Click "JES Functions"->"Turtles" We'll be using Object-oriented style when calling the turtle functions: fred.forward(95) instead of forward(fred, 95)

Worlds know what turtles are in them  Each time we add a turtle, the world keeps track  We can ask a world to tells what turtles are in it: getTurtleList(world)  It returns an array (linear collection) of turtles objects!  This is similar to getPixels(pic), which returns a linear collection of pixel objects

Recall what we know about operating on lists  We can access an element in the list using [ ]  We can iterate (loop) over a list of turtles just like we loop over a list of numbers  Recall how the for loop works!  Runs once for every element in the list  First time around stores the first element in the loop variable  Second time around, stores the second element in the loop variable  This continues until we get to the end of the list

Turtles know where they are in the world  Get a turtle’s position very easily… just ask it!  getXPos()  getYPos()