Chapter 4 Specification of a simple class. This chapter discusses n How to write the specifications for a class. u The precise description of features.

Slides:



Advertisements
Similar presentations
Chapter 5 Implementing a simple class. This chapter discusses n Implementing class definitions. n How to store data in an object and how to write method.
Advertisements

Chapter 8 Testing a class. This chapter discusses n Testing in general. n Testing a single class. n Test plans. n Building a test system.
Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Chapter 4 Specification of a simple class. This chapter discusses How to write the specifications for a class.  The precise description of features common.
CSCI 1100/ , 6.2, 6.4 April 12, 15, 17.
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.
Lecture 18: 4/11/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
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.
Utilities (Part 3) Implementing static features 1.
Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Chapter 14: Overloading and Templates
Object-Orientation in Query Languages By: Toan Nguyen Class: CS 157A.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
CS 117 Spring 2002 Classes Hanly: Chapter 6 Freidman-Koffman: Chapter 10, intro in Chapter 3.7.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
Chapter 8: User-Defined Classes and ADTs J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Chapter 5- Even more about objects and methods. Overview n Designing methods n Methods, methods, methods n Overloading methods n Constructor methods n.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Putting together a complete system Chapter 10. Overview  Design a modest but complete system  A collection of objects work together to solve a problem.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
Chapter 8: User-Defined Classes and ADTs
Agenda Object Oriented Programming Reading: Chapter 14.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Chapter 9 Putting together a complete system. This chapter discusses n Designing a complete system. n Overview of the design and implementation process.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Chapter 2 Data abstraction: introductory concepts.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
Classes, Interfaces and Packages
Chapter 7 Programming by contract: preconditions and postconditions.
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Chapter 12 Classes and Abstraction
TK1924 Program Design & Problem Solving Session 2011/2012
Arrays Chapter 7.
Java Programming: Guided Learning with Early Objects
Chapter 14 Templates C++ How to Program, 8/e
PHP Classes and Objects
Road Map Introduction to object oriented programming. Classes
User-Defined Classes and ADTs
Manipulating Pictures, Arrays, and Loops part 2
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 8: User-Defined Classes and ADTs
Implementing Classes Chapter 3.
Building a CORBA Server
Chapter 6 Conditions.
Arrays Chapter 7.
Anatomy of a Java Program
Implementing a simple class
Introduction to Computer Science
Presentation transcript:

Chapter 4 Specification of a simple class

This chapter discusses n How to write the specifications for a class. u The precise description of features common to all instances of the class. u Features of the server seen by the client. u Distinct from the implementation. n The client-server relationship between two objects. n Several example class specifications.

Client and Server n A client queries and commands a server. u Queries ascertain values of properties. u Commands change its state. n A client uses a server.

Client and Server (cont.)

Specification and implementation n specification: an object’s features, as seen by its clients. n implementation: the “internals” that make up the features.

Specification and implementation (cont.) n Specifications isolate you from the details of the implementation. u “I don’t care how you do it, just get the job done”(to specifications). u How the features are actually implemented by the server, is of no concern to the client. n Preserving the distinction between specification and implementation is absolutely essential.

Let’s start specifying n First, enumerate the object’s responsibilities. Then determine its properties and commands. n Java syntax does not allow us to separate a class specification from its implementation.

A simple counter A simple counter’s responsibilities: Know (one query): the value of the count Do (two commands): set the count to 0 increment the count by 1

A simple counter (cont.) n A simple counter Class: Counter Queries (Properties) : count (A non-negative integer) Commands: reset (sets count value to 0) step_count (increments the count by 1)

Specification documentation n Tools such as javadoc generate sets of HTML documents containing specifications extracted from program source files.

Invoking a method n method: a language construct that defines and implements a query or command. n In order to invoke a method, you must have an instance of the class call the method. Syntax: instance.method() Example: c.count()

Maze game example n An explorer (player) must navigate successfully through the rooms without being killed by denizen (monsters). n There can be several rooms and denizen, but only one explorer. n We need 3 classes: Explorer, Denizen, and Room.

Explorer responsibilities Know: his name his location in the maze damage inflicted upon an opponent damage received from an opponent his stamina Do: set or change name change location fight a maze Denizen

Invoking methods with parameters n To be invoked properly, a method sometimes requires information from the client. Information is passed in as parameters. n When a client invokes a method, the client must provide a value of the appropriate type for each parameter. Syntax: instance.method(p0,p1,p2…) n The only way an object’s state can change is by invoking one of the object’s methods.

Parameters and arguments n If we wish to change an explorer’s name, we must provide a new name. n If we wish to change an explorer’s location, we must provide either a new location or a movement from which the location can be determined. n The needed elements are referred to as the parameters of the command. n The actual values we provide are referred to as arguments.

Constructors n Can be used to set the initial values of an objects properties. n Examples: u A counter’s initial value of 0. u An explorer’s initial name, location, strength, and stamina.

Class Student n Consider a university registration system. u Students register for courses. F Each student is represented by a distinct object. F All students are members of the Student class. u The university F Assesses fees. F Prints student schedules. F Produces class rolls. F Etc.

Queries public String name () public String address () public String ssn () public int creditHours () public int fees () public int feesPaid () public courses.CourseList schedule()

Commands public void changeName () public void changeAddress () public void changeSsn () public void addCourse () public void dropCourse () public void payFees ()

Contructors public Student (String name, String address, String ssn)

We’ve covered n Specification of classes in Java. n Client-Server relationships. n Definitions of specification and implementation. n Several examples of simple class implementation.

Glossary

Glossary (cont.)