Fundamentals of Software Development 1Slide 1 Method invocation versus definition To define (write) a method means to write its codeTo define (write) a.

Slides:



Advertisements
Similar presentations
Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Advertisements

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Fundamentals of Software Development 1Slide 1 Recap: Constructors, the new operator and the this object Three ideas:Three ideas: –How to write a constructor.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
The Fundamental Rule for Testing Methods Every method should be tested in a program in which every other method in the testing program has already been.
Fundamentals of Software Development 1Slide 1 Review: Why start with WordGames? You wrote your first lines of code in this course in WordGames.You wrote.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Chapter 14: Overloading and Templates
Fundamentals of Software Development 1Slide 1 Why have interfaces? A Java interface is the “face” that one class shows othersA Java interface is the “face”
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Classes and Methods Write a class called C1 containing: A static variable SV of type int. A static method SM with one parameter, of type C1, and a void.
Fundamentals of Software Development 1Slide 1 Today’s Summary UML class diagrams – –Why classes are important – –UML class diagrams – relationships – –UML.
Fundamentals of Software Development 1Slide 1 One class can describe many different instancesOne class can describe many different instances –Two NameDroppers,
Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to.
Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts.
ECE122 L13: Arrays of Objects March 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 13 Arrays of Objects.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Parameters, Arguments, Local Variables, and Scope CSC 1401: Introduction to Programming with Java Week 8 – Lecture 1 Wanda M. Kunkle.
ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Fundamentals of Software Development 1Slide 1 Recap: Key ideas in WordGames Defining a classDefining a class Extending a class versus implementing an interfaceExtending.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Class Example - Rationals Rational numbers are represented by the ratio of two integers, a numerator and a denominator, e.g., 2/3. This is opposed to irrational.
1 CS161 Introduction to Computer Science Topic #10.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Object Oriented Programing (OOP)
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
 Implementing a class ◦ Implementing an interface ◦ Using documented stubs before coding ◦ Writing JUnit tests before coding ◦ Using fields CSSE 220 Object-Oriented.
Classes, Interfaces and Packages
1 Introduction to Object Oriented Programming Chapter 10.
Classes - Intermediate
Utilities (Part 2) Implementing static features 1.
© 2004 Pearson Addison-Wesley. All rights reserved November 12, 2007 Inheritance ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Fundamentals of Software Development 1Slide 1 Today’s Summary InterfacesInterfaces –What are they? –Why are they important? –How do they relate to WordGames?
Fundamentals of Software Development 1Slide 1 Recap: Key ideas in BallWorlds so far Writing a class:Writing a class: –structure –process Writing methods:Writing.
Recap: Key ideas in WordGames
Recap: The design of Word Games
Object-Oriented Concepts
Intro To Classes Review
Chapter 10: Void Functions
Delegates and Events 14: Delegates and Events
Organization of Programming Languages
Chapter 4: Writing Classes
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
CSC 113: Computer programming II
Name: Rubaisha Rajpoot
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Classes, Encapsulation, Methods and Constructors (Continued)
Array and Method.
Defining Classes and Methods
Constructors and Destructors
CIS 199 Final Review.
Fundamentals of Software Development 1
Classes, Objects and Methods
Functions Imran Rashid CTO at ManiWeber Technologies.
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
Chapter 4 Test Review First day
Presentation transcript:

Fundamentals of Software Development 1Slide 1 Method invocation versus definition To define (write) a method means to write its codeTo define (write) a method means to write its code –The code is a recipe to follow when the method runs –Methods often have parameters – information that comes into the method when it is run To invoke (call, run) a method means to cause the method’s code to runTo invoke (call, run) a method means to cause the method’s code to run –Sending it actual values to substitute for the formal parameters of the method Example (on next slides)Example (on next slides)

Fundamentals of Software Development 1Slide 2 Method invocation versus definition To define (write) a method means to write its codeTo define (write) a method means to write its code To invoke (call, run) a method means to cause the method’s code to runTo invoke (call, run) a method means to cause the method’s code to run Example (on next slide):Example (on next slide): –The NameDropper class in the blue box defines: A field called myName to hold the NameDropper’s name to dropA field called myName to hold the NameDropper’s name to drop A constructor called NameDropper that takes the name to store in the fieldA constructor called NameDropper that takes the name to store in the field A method called transform that takes a phrase to tranformA method called transform that takes a phrase to tranform –The statements in the yellow box cause the NameDropper constructor and transform method to run They each run several times, with different actual arguments substituted for the formal parameters in the NameDropper definitionThey each run several times, with different actual arguments substituted for the formal parameters in the NameDropper definition These statements would themselves appear in some other classThese statements would themselves appear in some other class

Fundamentals of Software Development 1Slide 3 public class NameDropper extends StringTransformer implements StringTransformable { private String myName; Public NameDropper(String nameToUse) { this.myName = nameToUse; } public transform(String phrase) { return this.myName + “says ” + phrase; } NameDropper person1, person2, person3; person1 = new NameDropper(“Calvin”); person2 = new NameDropper(“Hobbes”); person3 = new NameDropper(“lobster”); person1.transform(“you look funny today, Hobbes.”); person2.transform(“you looker even funnier.”); person1.transform(“no, YOU look funnier.”); person3.transorm(“I amd just a lonely lobster.”); Definition of the NameDropper class Invoking the NameDropper constructor and transform method