Develop Instantiable classes. Lesson plan What does that mean? Why do we have to create instantiable classes? How do we go about creating them? Practice.

Slides:



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

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Fields, Constructors, Methods
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Inheritance Inheritance Reserved word protected Reserved word super
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes and Objects Systems Programming.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
CS 106 Introduction to Computer Science I 03 / 19 / 2008 Instructor: Michael Eckmann.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Abstract Superclasses and Abstract Methods When.
Interfaces besides classes, Java recognizes another type, an interface interface is used to completely shield off all implementation from the programmer.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Ruby (on Rails) CSE 190M, Spring 2009 Week 4. Constructors Writing a new class is simple! Example: class Point end But we may want to initialize state.
Ruby (on Rails) Slides modified by ements-2ed.shtml) 1.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
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.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
Elements of a Java Program Bina Ramamurthy SUNY at Buffalo.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
1 CS161 Introduction to Computer Science Topic #9.
CS 106 Introduction to Computer Science I 10 / 29 / 2007 Instructor: Michael Eckmann.
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
1 Strings, Classes, and Working With Class Interfaces CMPSC 122 Penn State University Prepared by Doug Hogan.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Written by: Dr. JJ Shepherd
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved. Chapter 6 Slide.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Class Fundamentals BCIS 3680 Enterprise Programming.
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
Defining Classes. Why is Java designed this way? Improving our class Creating our own class Using our class Implementing our class.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
© 2004 Pearson Addison-Wesley. All rights reserved3-1 Objects Declaration: String title;  title (object variable) of type String( Class )  title is just.
OCR A Level F453: High level languages Programming techniques a. identify a variety of programming paradigms (low-level, object- oriented,
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Haidong Xue Summer 2011, at GSU
Chapter 3: Using Methods, Classes, and Objects
Interfaces.
Chapter 3 Introduction to Classes, Objects Methods and Strings
Object-oriented Design in Processing
Implementing Classes Chapter 3.
Object-oriented Design in Processing
JAVA CLASSES.
Object-oriented Design in Processing
Dr. R Z Khan Handout-3 Classes
Object-oriented Design in Processing
Classes and Objects Systems Programming.
Introduction to Computer Science and Object-Oriented Programming
Introduction to Classes and Objects
Presentation transcript:

Develop Instantiable classes

Lesson plan What does that mean? Why do we have to create instantiable classes? How do we go about creating them? Practice lab

Why do we have to create instantiable classes? What does that mean by instantiable classes? –We can create instances of these classes Example: (create objects from these classes) String DecimalFormat

Why do we have to create instantiable classes? Steps in LoanCalculator.java or AnnuityFund.java contains: Describe the program Get inputs from users Computation Display output to users

Why do we have to create instantiable classes? Is there any problems with this design? What if we need to solve a more complicated problem? Large method, impossible to manage If dealing with more complicated problem Pre defined classes (provided by Java library, Third party, etc..) don’t provide exactly what you need

How do we create instantiable classes? Understand the structure of a class Specification for the class –How the class (that we are going to create) interact with other classes? –Specify the behaviors and fields that this class supports Implementation

Structure of a class A class definition provides a description of a typical object within that class. A class has its behavior (methods) and attributes (fields) Example: class String attributes and behavior/method : length: returns the length of a string substring: returns a substring from the original string charAt: returns a character at a specific position

How a class interacts with other classes? When you are creating a class, we should think of the objects that can be created from this class. –Example: Class Student, each object should be an individual student (e.g studentA, studentB) What would be a natural and logical way to create an object? –Example: we can create a student object if we know his/her studentID, and name

How a class interacts with other classes? What would be a natural and logical way for us to interact with it (or to use it)? Harry: Hi! How are you? How is your Java midterm? Sally: Not too bad. I was working hard for the test though Harry: So what are you doing this week-end? Any plan in particular? We have a tailgate party before the football game. Wanna join? Sally: Sound great! See you there

How a class interacts with other classes? Analyze the conversation: How are you? Attribute: Health Value: well, good, tired… Java midterm: Attribute: Course Value: Java, Database, GenEd, French… Working hard: Attribute: Work Ethic Value: hard working, lazy, moderate… Tailgate party and football game Attribute: Hobby Value: party, football, basketball…

How a class interacts with other classes? Attribute: Health –Value: well, good, tired… How two students (objects) ask each other about this attribute: How are you? (One way of saying how is your health?) Therefore, we need a method in the Student class so that one student can provide an answer to another student if he/she is asked about his/her health Let’s name this method: howIsYourHealth Similarly: whatAreYourCourse? whatAreYourHobby?

How a class interacts with other classes? Step 1: Understand the purpose of the class that you are creating Step 2: Use your imagination to identify attributes and method for this class: What would be a natural and logical way to create an object? What would be a natural and logical way for an object of this class to interact with another object of the same class? Step 3: List them out on a paper

Implementation Class header and class body. Member definitions in the body. –Methods and attributes. // class called ClassName. class ClassName { // Attribute definitions go in the class body // Method definitions go in the class body... } Class Header

Implementation For each attribute, determine the followings: What does it represent? Example: attribute: health represents a student’s well-being. Which datatype does we use to represent this attribute? This can be determined from the possible values that this attribute will be assigned. Example: attribute: health. possible values: tired, excellent, good,…etc possible datatype: String Any default value for this attribute: Example: good

Implementation Declare an attribute in a class in the same way you declare a variable: ; Example:String health; Then add modifier (private or public) in front of the attribute declaration Example:private String health You can initialize an attribute with its default value as: = ; Example: private String health=“good”;

Implementation For each method, determine the followings: What does it do? –E.g: howIsYourHealth answers the question about your health. It will return the value representing your health (whether you are tired, feeling well or not..) What does it return? –E.g howIsYourHealth returns a string (“tired”, or “well”…) What are the parameters it requires? (parameter: additional information) –E.g howIsYourHealth did not require any parametter –howIsYouCourse require a course number