1 Objects and Classes: creating simulations Powerpoint created by Beverly McGuire.

Slides:



Advertisements
Similar presentations
Basic Object-Oriented concepts. Concept: An object has behaviors In old style programming, you had: –data, which was completely passive –functions, which.
Advertisements

Georgia Institute of Technology Creating Sounds and MIDI part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
TOPIC 12 CREATING CLASSES PART 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
AbstractClassesInterfacesPolymorphism1 Abstract Classes, Interfaces, Polymorphism Barb Ericson Georgia Tech April 2010.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Road Map Introduction to object oriented programming. Classes
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Classes and Objects in Java
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Object-oriented Programming Concepts
Terms and Rules Professor Evan Korth New York University (All rights reserved)
ASP.NET Programming with C# and SQL Server First Edition
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Games and Simulations O-O Programming in Java The Walker School
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
04-Intro-Object-Oriented-In-Java1 Barb Ericson Georgia Institute of Technology Sept 2009 Introduction to Object-Oriented Programming in Java.
Introduction To Object-Oriented Programming. Object-Oriented Programming Class: Code that defines the behavior of a Java programming element called an.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 1.
CPSC1301 Computer Science 1 Chapter 11 Creating Classes part 1.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CreatingClasses-part11 Creating Classes part 1 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 2.
Georgia Institute of Technology Declaring Variables – Mod 4 Barb Ericson Georgia Institute of Technology August 2005.
More about Class 靜宜大學資工系 蔡奇偉副教授 ©2011. 大綱 Instance Class Members Class members can be associated with an instance of the class or with the class as a.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
Java Introduction part 2 CSC1401. Overview In this session, we are going to examine some of the instructions from the previous class in more detail.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Georgia Institute of Technology Declaring Variables – Mod 4 Barb Ericson Georgia Institute of Technology August 2005.
Copyright Curt Hill Variables What are they? Why do we need them?
CreatingSubclasses1 Barb Ericson Georgia Institute of Technology Dec 2009.
Computer Science 111 Fundamentals of Computer Programming I Working with our own classes.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
CSE 143 Lecture 12 Inheritance slides created by Ethan Apter
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology Aug 2006 Introduction to Object-Oriented Programming in Alice and Java.
Georgia Institute of Technology More on Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Georgia Institute of Technology More on Creating Classes part 3 Barb Ericson Georgia Institute of Technology Nov 2005.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Basic Object-Oriented concepts. Concept: Classes describe objects Every object belongs to (is an instance of) a class An object may have fields –The class.
Georgia Institute of Technology Comic Strip Analysis and Design Inheritance, Abstract Classes, and Polymorphism part 2 Barb Ericson Georgia Institute of.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology Sept 2006 Introduction to Object-Oriented Programming in Alice and Java.
Georgia Institute of Technology Comic Strip Analysis and Design Inheritance, Abstract Classes, and Polymorphism part1 Barb Ericson Georgia Institute of.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
2-Oct-16 Basic Object-Oriented Concepts. 2 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions,
Object-Oriented Databases
Declaring Variables – Mod 4
University of Central Florida COP 3330 Object Oriented Programming
Teaching Java using Turtles part 1
Interface.
Declaring Variables – Mod 4
Unit-1 Introduction to Java
Interfaces.
Barb Ericson Georgia Institute of Technology Oct 2005
Introduction to Object-Oriented Programming in Alice
Tonga Institute of Higher Education
Workshop for Programming And Systems Management Teachers
More on Creating Classes
Object Oriented Programming
More on Creating Classes part 3
Use a variable to store a value that you want to use at a later time
Teaching Java using Turtles
Presentation transcript:

1 Objects and Classes: creating simulations Powerpoint created by Beverly McGuire

2 Objects Objects are the things that do the action or are acted upon in a simulation. Objects can have data (fields) and behavior (methods). Every object is an instance of a class (its classification or type). The class creates the objects since it knows how big the object needs to be (how many and what type of fields). All objects keep a reference to the class that created them (they know their type).

3 What does this mean? If you go to a restaurant you may be greeted by the greeter and shown to your table. The waiter will take your order and bring you your food. The chef will cook the food. If we want to make a simulation of this we will have objects of the type: Greeter, Waiter, Chef, Customer, Order, Food, and so on. We can have more than one object of each class. There will usually be several waiters and many customers.

4 What are Objects used for? Classes define the data (fields) that objects of that classification will have and the things that they will be able to do (methods). Classes create objects. Objects act in the simulation.

5 Analogies: Job descriptions are like classes. Workers in those jobs are like the objects. A class is also like a blueprint or cookie cutter. Objects are like houses built based on the blueprints or like cookies made with the cookie cutter.

6 How Create an Object: You ask the class to create a new object using the new keyword: new Class(parameter list) You can create a new String object by the following: String name = “Susan";

7 An Example of Creating an Object: new World(); new Turtle(new World());

8 Creating a Class: Classes are defined in files. Each class is usually defined in its own file. The file name is the same as the class name with an extension of ".java".

9 Creating a Class: (cont.) You define a class using the class keyword: visibility class Name or visibility class Name extends ParentClass visibility is usually public meaning all other classes can use it

10 Creating a Class: (cont.) Name is the name of the class. By convention each word in a class name starts with an uppercase letter like SimpleTurtle. ParentClass is the name of the class this class inherits from. If a parent class isn't specified the parent is Object.

11 Creating a Class Common Errors: Forgetting to declare a variable to hold a reference to a new object  If you create a new object but don't declare a variable to keep track of the reference you won't have any way to refer to it again. The object will be garbage collected and the memory it uses will be released.  new Turtle(new World());

12 Creating a Class Common Errors: Not declaring a class in a file with the same name Don’t try to save out a class into a new file with a different name. The name of the class and the file must match.

13 Special thanks to Barb Ericson for providing Concept Cards for this presentation