ACM/JETT Workshop - August 4-5, 2005 1 03.Object-Oriented Basics & Design.

Slides:



Advertisements
Similar presentations
Object Oriented Programming. Object Oriented Data and operations are grouped together Account Withdraw Deposit Transfer Interface: Set of available operations.
Advertisements

Class Relationships Part 1: Composition and Association CS 21a: Introduction to Computing I First Semester,
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
1 Objects, Classes, and Packages “Static” Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in.
Inheritance Part I. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
I NHERITANCE Chapter 10. I NHERITANCE Mechanism for enhancing existing classes You need to implement a new class You have an existing class that represents.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Classes Object-oriented programming: Model the problem as a collection of objects that have certain attributes and interact with one another and/or the.
Ch 12: Object-Oriented Analysis
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
April 20023CSG11 Electronic Commerce Java (1) John Wordsworth Department of Computer Science The University of Reading Room 129,
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
Chapter 9: Classes with Instance Variables or Classes=Methods+Variables Asserting Java © Rick Mercer.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 7 Object-Oriented Programming.
ACM/JETT Workshop - August 4-5, 2005 UML Modeling using MagicDraw UML for Java Programmers.
Object Oriented Programming. Problem Description “ …customers are allowed to have different types of bank accounts, deposit money, withdraw money and.
Introduction To System Analysis and design
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
CMP-MX21: Lecture 6 Objects & Methods 1 Steve Hordley.
Writing Classes (Chapter 4)
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Module 7: Object-Oriented Programming in Visual Basic .NET
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
CS212: Object Oriented Analysis and Design Lecture 4: Objects and Classes - I.
Introduction to Object-Oriented Programming
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
ACM/JETT Workshop - August 4-5, Guidelines For Using BlueJ.
Introduction To System Analysis and Design
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
Chapter 3 Implementing Classes. Assignment Read 3.1 – 3.5 and take notes complete Self Check Exercises 1-10; Due September 24 th Read 3.6 – 3.8 and take.
1 21 COP 3540 Data Structures with OOP Overview: Chapter 1.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
1 Strings, Classes, and Working With Class Interfaces CMPSC 122 Penn State University Prepared by Doug Hogan.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Wednesday –POD –I have updated grades in powerschool. If you have a zero for a lab grade, it probably means you didn’t DropItToMe. Please do so. –Slides.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Classes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
What About Alice? In Alice, we have seen that we have:  Objects (skater, snowman, snowwoman, camera)  Methods (move, turn, roll, move toward)  Properties.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Outline Anatomy of a Class Encapsulation Anatomy of a Method Graphical Objects Graphical User Interfaces Buttons and Text Fields Copyright © 2012 Pearson.
OOP in C# - part 1 OOP in C#: –Object Interaction. –Inheritance and Polymorphism (next module). FEN 20121UCN Technology: Computer Science.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
Chapter 3 Implementing Classes
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Java OOP Overview Classes and Objects, Members and Class Definition, Access Modifier, Encapsulation Java OOP Overview SoftUni Team Technical Trainers.
Classes and OOP.
Chapter Three - Implementing Classes
Anatomy of a Method.
CS100J Lecture 7 Previous Lecture This Lecture Java Constructs
JAVA CLASSES.
Introduction to Object-Oriented Programming
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

ACM/JETT Workshop - August 4-5, Object-Oriented Basics & Design

ACM/JETT Workshop - August 4-5, Topics In this Lecture, we will discuss the some of the fundamental notions in Object-Oriented systems: –Encapsulation of data and functions as objects. –Class vs object –Information hiding using public and private –Creating instances /objects from classes. –Calling methods on objects –Instance vs class-level data members. –Java code segments to illustrate these concepts.

ACM/JETT Workshop - August 4-5, What to expect After this lecture, you should be able to use the given code in BankAccount.java file and do the following: –Add a new method to class BankAccount. –Create instances from class BankAccount. –Use the methods defined in BankAccount –Compile and test your code.

ACM/JETT Workshop - August 4-5, 2005 An Object-Oriented System An object-oriented system consists of a network of objects which collaborate to solve a problem. Objects store data and perform actions. bankaccount bank customer showBalance (acctId) getBalance()

ACM/JETT Workshop - August 4-5, 2005 An Object-Oriented (OO) System To understand the object-oriented concepts and OO design, we will study a small part of an application area that we are all familiar with: banking. A simple specification of banking: A bank maintains a collection of bank accounts, where a bank account can be a checking or a savings account. Each bank account is associated with a customer. A customer queries,deposits and/or withdraws money into a bank account.

ACM/JETT Workshop - August 4-5, 2005 An Object-Oriented System The figure below shows some of the objects in the specification and a scenario where a customer calls a showBalance() function on a bank object; in turn, a bank object calls getBalance() function on a bank account object. bankaccount bank customer showBalance (acctId) getBalance()

ACM/JETT Workshop - August 4-5, 2005 What are Objects? Objects are “ things” that encapsulate data and behavior (actions called methods). Objects can be “physical” things (eg: teacher, book, fish). Objects can be “conceptual” things (eg: registration, payment, bank account). Objects correspond to “nouns” in problem description.

ACM/JETT Workshop - August 4-5, What are objects? Objects encapsulate data and behavior. A Bank Account object has –acctId –balance –calcInterest () –deposit () –withdraw () –getBalance() data methods (functions) (behavior)

ACM/JETT Workshop - August 4-5, What are objects? Objects may have an internal structure (private). –Eg: A bank account may store an acctId, balance etc. Objects reveal themselves by their external behavior (public methods). –Eg: A back account object may be used with its public methods, like deposit and withdraw.

ACM/JETT Workshop - August 4-5, What are objects? Objects reveal their “public behavior” but keep their "inside (or implementation)" hidden. The “public behavior” of objects is through a set of methods (functions) that are offered to clients of objects. The methods (functions) can be invoked by clients. A client is an object that invokes the methods of an object.

ACM/JETT Workshop - August 4-5, Objects = data + methods An object of type BankAccount acctId deposit() withdraw() privatepublic calcInterest() balance getBalance() Client A client can call any public methods data methods

ACM/JETT Workshop - August 4-5, What is a class A class is a software blueprint that defines the variables and the methods common to all objects of a certain kind. A class can be used and reused many times to create many objects. A class is one mechanism to define new types in Java. Objects are created as instances of a class.

ACM/JETT Workshop - August 4-5, Information hiding In a class, public features can be seen and manipulated by anybody -- they are the external (interface) view. private features can be manipulated by only the other members of that class. They are the internal (implementation) view. Good OO design recommends that –methods are public and –data fields are private.

ACM/JETT Workshop - August 4-5, Class vs Object acctId deposit() withdraw() privatepublic calcInterest() balance getBalance() acctId= A12 deposit() withdraw() privatepublic calcInterest() Balance= getBalance() BankAccount – a class myAccount – an object of type BankAccount

ACM/JETT Workshop - August 4-5, Class vs Object How do you define a class in Java? Show class BankAccount Example1_3 Show class BankAccount Example1_3

ACM/JETT Workshop - August 4-5, Creating objects from a class Objects are created by instantiating a class. An object is also called an instance. In Java, you create an object from a class using new().

ACM/JETT Workshop - August 4-5, Creating objects from a class // Declare a variable // of type BankAccount BankAccount myAcct; myAcct // Create an instance of type BankAccount // Store the reference in the variable // myAcct myAcct = new BankAccount(); acctId = “Not set” Balance = 0.0 myAcct

ACM/JETT Workshop - August 4-5, Calling Methods of an objects The public methods of an object can be invoked with a. (dot) operator. Example: BankAccount myAcct; myAcct = new BankAccount(); // deposit $ by invoking the // deposit() method on myAcct myAcct.deposit(100.00);

ACM/JETT Workshop - August 4-5, Instance data members of an object // Declare a variable of type BankAccount BankAccount myAcct; myAcct = new BankAccount(); BankAccount acct2 = new BankAccount(); // deposit into myAcct. myAcct.deposit(100.00); // deposit into acct2. acct2.deposit(500.00); myAcct acctId = “Not set” balance = 0.0 acct2 acctId = “Not set” balance = 0.0 The instances myAcct and acct2 have their own copy of the data members, balance and acctId (instance data members)

ACM/JETT Workshop - August 4-5, Class-level Data members Assume that we want to include the fact that the current interest rate for all bank accounts is 5%. If the rate changes, all bank account instances should have the same rate. In this case, we can define the interest rate as a class level data member. In Java, class-level members are called static members. Both data and methods can be static.

ACM/JETT Workshop - August 4-5, Class-level Data members Methods that are static can only access static data members. Static methods can be called on a class without creating an instance. Example: BankAccount myAcct = new BankAccount(); // Calling an instance method on an instance myAcct.deposit (100.00); // Calling a static method on a class double rate = BankAccount.getRate();

ACM/JETT Workshop - August 4-5, Class-level Data members Show class BankAccount Example2_3 Show class BankAccount Example2_3

ACM/JETT Workshop - August 4-5, State of an object The state of an object is described by the values of (some or all) of its data members. Example: The state of a bank account object would include the current balance.

ACM/JETT Workshop - August 4-5, When do objects change their state? Objects change their state as a result of executing a method. Example: The state of a BankAccount object (with a current balance of $0) will change when a deposit() or withdraw() method is invoked on that object.

ACM/JETT Workshop - August 4-5, The topics that you should be comfortable with at this time Class vs object How to define a class in Java private vs public members of a class Creating instances/objects from classes in Java. Calling instance methods on objects and Calling class methods on class/object using the Java code segments given.

ACM/JETT Workshop - August 4-5, To test your understanding Do Lab 1