OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

CIT 590 Intro to Programming Java lecture 3. Hashmaps The equivalent of python dictionaries. With both ArrayLists and Hashmaps, the syntax only allows.
OBJECT-ORIENTED PROGRAMMING CONCEPTS (Review). What is an Object? What is an Object? Objects have states and behaviors. Example: A dog has states - color,
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Lecture 28 More on Exceptions COMP1681 / SE15 Introduction to Programming.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
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,
Introduction to Programming with Java, for Beginners Intro OOP with Java Java Program Structure.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Objects First with Java A Practical Introduction using BlueJ
Copyright by Scott GrissomCh 1 Objects and Classes Slide 1 Classes and Objects A Class refers to something in general describes a category of items a cookie.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Introduction to Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
Understanding class definitions Looking inside classes.
Object-Orientated Design and Programming Unit 9: Abstract Classes and Interfaces Jin Sa.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
MIT AITI 2003 Lecture 7 Class and Object - Part I.
1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  software objects, classes, object-oriented design  BlueJ IDE, compilation.
Lecture 1 Introduction to Java MIT- AITI 2004 What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word.
Object Oriented Software Development
1 Programming James King 12 August Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
Introduction to Object-Oriented Programming
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.
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
Java Classes Methods Objects. Classes Classes We have been using classes ever since we started programming in Java Whenever we use the keyword class.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.
Chapter 1 - Getting to know Greenfoot
Chapter 1 Object Orientation: Objects and Classes.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
1 CSC 221: Computer Programming I Spring 2008 Objects and classes: a broad view  software objects, classes, object-oriented design  BlueJ IDE, compilation.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Salman Marvasti Sharif University of Technology Winter 2015.
1 CSC 221: Computer Programming I Fall 2009 Objects and classes: a broad view  Scratch programming review  object-oriented design, software objects 
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved. Chapter 6 Slide.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create.
Object and Classes อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 3.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Chapter 1 Object Orientation: Objects and Classes.
Week 21 Introduction to Programming Ms. Knudtzon C Period Lecture 3.
Objects as a programming concept
Objects as a programming concept
Objects and Classes CITS1001 week 1.
Objects First with Java A Practical Introduction using BlueJ
Objects as a programming concept
Object Oriented Programming
OBJECT ORIENTED CONCEPTS
Objects First with Java A Practical Introduction using BlueJ
What is an object? An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the.
Java Programming with BlueJ
COS 260 DAY 2 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Workshop for Programming And Systems Management Teachers
Objects First with Java A Practical Introduction using BlueJ
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
References Revisted (Ch 5)
Presentation transcript:

OBJECTS AND CLASSES CITS1001

Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method calling; source code; method result Reading: Objects First with Java, Chapter 1 2

Objects represent ‘things’ from the real world, or from some problem domain e.g. the red car down there in the car park e.g. the lecturer talking to you now e.g. you! Classes represent all objects of a certain kind e.g. Car, Lecturer, Student A class is a group of objects that have similar characteristics and that exhibit similar behaviour An object is a specific instance of a class Classes and objects 3

Example The set of all students forms the class Student Each individual student is an object of the class Student John Smith and Janice Lee are instances of Student 4

Example The set of all dogs forms the class Dog Each individual dog is an object of the class Dog Spot, Rover, and Rex are all instances of Dog 5

Why do we use classes? To reduce complexity Often, we know how to deal with an object based purely on knowing its class, without knowing anything specifically about that particular instance For example, if we encounter a dog – i.e. an instance of the class Dog – we already have a basic understanding of how to deal with it, even if we have never previously met that particular dog We know that it might bark, or bite, or wag its tail, based purely on knowing that it is a Dog Barking, biting, and tail-wagging are best viewed as features of the class Dog, not of any individual dog 6

Describing a class We describe a class by listing the common features that are shared by all the objects in that class The attributes that each object has, and The actions that each object can perform Student number is an attribute of the class Student Every student has a student number; although each individual student has a different student number Barking is an action that all objects of the class Dog do Every dog barks; although different dogs do it differently, based on the attributes of a given individual 7

What is a Waiter ? A Waiter has the following attributes Name Tax File Number And the following actions Bring menus Take orders Bring meals This collection of attributes and actions defines the class of Waiters We can deal with any individual waiter, whether we have met them before or not, based solely on our knowledge of the class Waiter 8

Exercise Download and open the shapes BlueJ project Create objects from the classes Circle, Square, Triangle Right-click on the class and select new(...) Inspect the objects Double-click on any object in the object bench Invoke their methods Right-click on an object and select one of its methods Experiment! Making mistakes is OK – it is a good way of learning to program! 9

What's in an object? Objects have operations that can be invoked Java calls these methods An object usually does something when we invoke a method Objects have state The state is represented by the stored values of attributes in “fields” The state of an object is a “snapshot” of that object at a particular moment in time e.g. the class Student might have An attribute studentNumber, that never changes, and An attribute booksBorrowed, that does change 10

Object state Notice the types of the fields: int, String, boolean Types restrict the values that a field can take 11

Instances Multiple instances: Many similar objects can be created from a single class An object has attributes: values stored in fields The class defines what fields an object has Each object stores its own set of values (the state of the object) 12

A Java method /** * Move the circle horizontally by * 'distance' pixels. */ public void moveHorizontal(int distance) { erase(); xPosition += distance; draw(); } 13

About methods Methods often have parameters Parameters pass additional information needed to execute the method i.e. “input” to the method Parameters have types The type defines what kinds of values a parameter can take Methods may also return a result via a return value The head of a method is called its signature The signature describes the information needed to invoke the method Objects communicate by calling each other’s methods 14

Source code The source code of a class specifies three things The form of the state of each object i.e. what fields it has The behaviour of each object i.e. what methods it has How objects are created i.e. how the fields are initialized by a constructor A Java application is a collection of classes 15

Return values All of the methods in the figures project have void return types; but … … methods may return a result via a return value Such methods have a non-void return type More on this in future lectures 16

Summary of concepts introduced You should now be able to give an explanation of each of these terms object; class; method; parameter; signature; data type; multiple instances; state; method calling; source code; result Try it! Turn to code example 1 17