COMP 14: decomposition, overloading, relationships June 7, 2000 Nick Vallidis.

Slides:



Advertisements
Similar presentations
This is Java Jeopardy Writing Methods…chapter 4…
Advertisements

© 2011 Pearson Education, publishing as Addison-Wesley Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science.
Interfaces A Java interface is a collection
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
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.
Chapter 4: Writing Classes
Chapter 4: Writing Classes
© 2006 Pearson Education Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Chapter 3, More on Classes & Methods Clark Savage Turner, J.D., Ph.D. Copyright 2003 CSTurner, from notes and text.
COMP 14: Arrays June 13, 2000 Nick Vallidis. Announcements zP5 goes out today.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Foundations of Program Design Writing Classes. 2 Objects b An object has: state - descriptive characteristicsstate - descriptive characteristics behaviors.
Enhancing classes Visibility modifiers and encapsulation revisited
ECE122 L16: Class Relationships April 3, 2007 ECE 122 Engineering Problem Solving with Java Lecture 16 Class Relationships.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
COMP 110 Introduction to Programming Mr. Joshua Stough October 24, 2007.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Third Edition by John Lewis and William Loftus.
Aalborg Media Lab 28-Jun-15 Software Design Lecture 7 “Object Oriented Design”
ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.
COMP 14: Writing Classes June 6, 2000 Nick Vallidis.
Methods in Java Selim Aksoy Bilkent University Department of Computer Engineering
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science by John Lewis, William Loftus, and Cara Cocking Java.
1 (c) elsaddik CSI 1102 Introduction to Software Design Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE.
1 Lecture 4 Objects and Classes Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science.
CSE 1301 Lecture 11 Object Oriented Programming Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
© 2004 Pearson Addison-Wesley. All rights reserved November 9, 2007 Method Design & Method Overloading ComS 207: Programming I (in Java) Iowa State University,
6-1 Object-Oriented Design Today we focuses on: –the this reference (Chapter 7) –the static modifier (Chapter 7) –method overloading (Chapter 7)
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.
CSE 1302 Lecture 7 Object Oriented Programming Review Richard Gesick.
© 2006 Pearson Education Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Chapter 6 Object-Oriented Design. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Object-Oriented Design Now we can extend our discussion of the.
Introducing Objects and stuff GABY and MATT Definition: Object: “a class that is the root of the hierarchy tree for all classes in JAVA.” –An object.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
1 Objects and Classes Introduction zNow that some low-level programming concepts have been established, we can examine objects in more detail zLecture.
Lecture 4 b Writing Classes b class declarations b method declarations b constructors b instance variables b encapsulation b method overloading b program.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science.
Chapter 4: Writing Classes. 2 b We've been using predefined classes. Now we will learn to write our own classes to define new objects b Chapter 4 focuses.
93 4/11/98 CSE 143 Class Constructors [Sections ]
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science.
Classes - Intermediate
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
© 2004 Pearson Addison-Wesley. All rights reserved November 12, 2007 Inheritance ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
© 2004 Pearson Addison-Wesley. All rights reserved April 10, 2006 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
1 Chapter 4: Writing Classes  Chapter 4 focuses on: class definitions encapsulation and Java modifiers method declaration, invocation, and parameter passing.
© 2004 Pearson Addison-Wesley. All rights reserved November 14, 2007 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, FALL.
© 2004 Pearson Addison-Wesley. All rights reserved April 5, 2006 Method Design & Method Overloading ComS 207: Programming I (in Java) Iowa State University,
Object-Oriented Design Chapter 7 1. Objectives You will be able to Use the this reference in a Java program. Use the static modifier for member variables.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
COMP 14 Introduction to Programming Mr. Joshua Stough March 23, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Chapter 4: Writing Classes
Chapter 4: Writing Classes
Inheritance November 10, 2006 ComS 207: Programming I (in Java)
Lecture 11 B Methods and Data Passing
Inheritance April 7, 2006 ComS 207: Programming I (in Java)
CSCI 1100/1202 April 10,
Classes, Encapsulation, Methods and Constructors (Continued)
CS139 October 11, 2004.
Lecture 11 Parameters CSE /26/2018.
Chapter 4: Writing Classes
Presentation transcript:

COMP 14: decomposition, overloading, relationships June 7, 2000 Nick Vallidis

Announcements zMidterm exam is on Friday zReview tomorrow

Homework zread zassignment P4 is due next Tuesday! (doing it is a good way to study for the exam…) z me any questions you'd like me to answer in the review tomorrow (do this before tomorrow morning)

Review zWhat is encapsulation? zWhat is an abstraction? zWhat are the visibility modifiers and what do they do? zHow is a method declared?

Today zConstructors zObject relationships zMethod overloading zMethod Decomposition

Constructors zA constructor is a special method that is used to set up a newly created object zThe programmer does not have to define a constructor for a class yThere is a "default constructor" automatically created for you that does nothing.

Constructors zWhen writing a constructor, remember that: yit has the same name as the class yit does not return a value  it has no return type, not even void yit often sets the initial values of instance variables

Object relationships zAn aggregate object is an object that contains references to other objects  An Account object is an aggregate object because it contains a reference to a String object (p. 189) zAn aggregate object represents a has-a relationship zA bank account has a name

Object relationships zSometimes an object has to interact with other objects of the same type  For example, we might concatenate two String objects together as follows s3 = s1.concat(s2);  One object ( s1 ) is executing the method and another ( s2 ) is passed as a parameter

Method overloading zMethod overloading is the process of using the same method name for multiple methods zThe signature of each overloaded method must be unique zThe signature includes the number, type, and order of the parameters

Method overloading zThe compiler must be able to determine which version of the method is being invoked by analyzing the parameters zThe return type of the method is not part of the signature

Method overloading float tryMe (int x) { return x +.375; } Version 1 float tryMe (int x, float y) { return x*y; } Version 2 result = tryMe (25, 4.32)Invocation

Overloaded methods  The println method is overloaded: println (String s) println (int i) println (double d)  The following lines invoke different versions of the println method: System.out.println ("The total is:"); System.out.println (total);

Overloading constructors zConstructors can be overloaded zAn overloaded constructor provides multiple ways to set up a new object

Method decomposition zA method should be relatively small, so that it can be readily understood as a single entity zA potentially large method should be decomposed into several smaller methods as needed for clarity zTherefore, a service method of an object may call one or more support methods to accomplish its goal

Guideline for decomp. zA general rule is to make your methods small enough so that they can fit on one screen zDefinitely ok to be shorter zcan be longer if decomposing it introduces unnecessary complexity