Objects and Classes CITS1001 week 1.

Slides:



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

More Sophisticated Behaviour 1 Using library classes to implement more advanced functionality.
Fields, Constructors, Methods
CITS1001 OBJECT ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING Semester 1, 2015: Introduction and Admin Dr. Lyndon While Computer Science & Software Engineering.
Further abstraction techniques Abstract classes and interfaces 5.0.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
More sophisticated behaviour Using library classes to implement some more advanced functionality.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Objects First with Java A Practical Introduction using BlueJ
String Concatenation (operator overloading) 3.0.
Understanding class definitions Looking inside classes 3.0.
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.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
1 Reflecting on the ticket machines Their behavior is inadequate in several ways: –No checks on the amounts entered. –No refunds. –No checks for a sensible.
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.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
1 CSC 221: Computer Programming I Fall 2004 Objects and classes: a first pass  software objects, classes, object-oriented design  BlueJ IDE, compilation.
1 Programming James King 12 August Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
Object Oriented Design: Identifying Objects
Objects First With Java A Practical Introduction Using BlueJ Designing applications 1.0.
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
OBJECTS AND CLASSES CITS1001. Concepts for this lecture class; object; instance method; parameter; signature data type multiple instances; state method.
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.
1 COS 260 DAY 1 Tony Gauvin. 2 Agenda Class roll call Instructor Introduction Instructor’s Educational Philosophy Contract on Classroom Behavior Syllabus.
Classes CS 21a: Introduction to Computing I First Semester,
1 CSC 221: Computer Programming I Spring 2008 Objects and classes: a broad view  software objects, classes, object-oriented design  BlueJ IDE, compilation.
Understanding class definitions
Designing applications Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns Objects First with Java - A Practical.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Testing. Have you contacted your project members lately?
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
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.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Chapter 1 Object Orientation: Objects and Classes.
Class definitions CITS1001 week 2.
COS 260 DAY 1 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Object Oriented Programming
Object INTERACTION CITS1001 week 3.
Objects First with Java
Understanding class definitions
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
Understanding class definitions
Chapter 4: Writing classes
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 2 Tony Gauvin.
Classes, Encapsulation, Methods and Constructors (Continued)
COS 260 DAY 18 Tony Gauvin.
COS 260 DAY 3 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Understanding class definitions
Objects First with Java Creating cooperating objects
COS 260 DAY 4 Tony Gauvin.
Workshop for Programming And Systems Management Teachers
Objects First with Java Creating cooperating objects
Objects First with Java A Practical Introduction using BlueJ
Classes CS 21a: Introduction to Computing I
COS 260 DAY 6 Tony Gauvin.
Further abstraction techniques
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Presentation transcript:

Objects and Classes CITS1001 week 1

Objects and Classes: --- and --- are objects of the class ----

Objects First with Java Fundamental concepts Class Object Instance method parameter signature Reading: Chapter 1 of Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling © David J. Barnes and Michael Kölling

Objects and classes Class Object Instance Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Objects and classes Class A class represents a general category of things e.g. Car, Bicycle, Student, Dog Object Individual objects are created from a class Objects represent ‘things’ from some real-world problem domain e.g: “the red car down there in the car park” Instance Each created instance of a class possesses its own copy of the characteristics of the class

Example - Student The set of all students forms the class Student A class describes features in common Each individual student is an object of the class Student John Smith and Janice Lee are instances of Student

Example - Dog 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

Example – Restaurant Writing programs is largely about managing complexity How is something complex organized in the real world? Consider a restaurant ... Diners want meals Chefs prepare dishes Waiters take orders, and bring food to the tables Busboys collect and wash plates Barmen prepare and serve drinks The maitre’d makes reservations and seats diners Each type of person provides a narrow range of services. The restaurant involves the co-operative interaction of all the restaurant staff and clients.

A Restaurant Jan Bob Ted Diner Waiter Chef Chicken and bok choy, please No. 14 and No. 67 Jan Bob Ted <meal> <dishes> Your meal, madam Ding! Diner Waiter Chef

What is a Waiter ? A Waiter has the following actions Bring menus Take orders Bring meals We can deal with any individual waiter, whether we have met them before or not, based solely on our knowledge of what things a Waiter can do

Review (1) Class Object Instance Objects are created from classes. The class describes the kind of object; the objects represent individual instantiations of the class. Object Java objects model specific objects from the problem domain. Instance Many similar objects can be created from a single class.

Review questions Can a class have several different objects? Discuss Can an object have several different classes? Discuss

Methods and parameters Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Methods and parameters Objects have operations which can be invoked (Java calls them methods). Q: what methods can be invoked on a Circle object? Methods may have parameters to pass additional information needed to execute. Q: Give some examples of methods from the Circle class and their parameters The header of a method is called its signature. It provides information needed to invoke that method. Q: What is the signature of the changeSize method?

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling State

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Two circle objects

Other observations Many instances can be created from a single class. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Other observations Many instances can be created from a single class. The class defines what fields an object has, but each object stores its own set of values (the state of the object). Parameter Methods can have parameters to provide additional information for a task. Signature The header of a method is called its signature. It provides information needed to invoke that method. Types Parameters have types. The type defines what kinds of values a parameter can take.

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Source code Each class has source code (Java code) associated with it that defines its details (fields and methods). We will start looking inside source code next week

Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Return values All 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 the next chapter.

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!

Review (2) Method Parameter Type Signature We can communicate with objects by invoking methods on them. Objects usually do something if we invoke a method. Parameter Methods can have parameters to provide additional information for a task. Type Parameters have types. The type defines what kinds of values a parameter can take. Signature The header of a method is called its signature. It provides information needed to invoke that method.

Review (3) State Method calling Source code Result Objects have state. The state is represented by storing values in fields. Method calling Objects can communicate by calling each other’s methods. Source code The source code of a class determines the structure and behaviour (the fields and methods) of each of the objects of that class. Result Methods may return information about an object via a return value.

Review questions Write the signature for a method named AddStudent that has one parameter of type String and does not return a value. Write the signature for a method named max that has two paramters both of type int, and returns an int value.

Review these concepts Watch David Barnes’ Intro to Key Concepts here: https://www.youtube.com/watch?v=CPUaTT0Xoo4&list=PLYPWr4ErjcnzWB95MVvlKArO6PIfv1fHd&index=1