Week 11: Case study: Designing, building, & testing a Person class Background for the Project Needed in many applications Is it possible? practical?

Similar documents
Session 3b: Defining data items

Week 2: The Clojure Language. Background Basic structure A few of the most useful facilities. A modernized Lisp. An insider's opinion

Week 6: Data. Let's focus first on application domain data.

Session 3: Data. Session 3a: Data

Ways of documenting Session 5: detailed requirements The Data Dictionary one any The Project A data dictionary Data Dictionary may be maintained

Ways of documenting Session 5: detailed requirements The Data Dictionary one any The Project A data dictionary Data Dictionary may be maintained

Session 4b: Review of Program Quality

CS103 Spring 2018 Mathematical Vocabulary

Does anyone actually do this?

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Skill 1: Multiplying Polynomials

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Session 2. Getting started with a well-structured system specification

Instructor: Craig Duckett. Lecture 04: Thursday, April 5, Relationships

MITOCW watch?v=kz7jjltq9r4


In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

Week 5: Background. A few observations on learning new programming languages. What's wrong with this (actual) protest from 1966?

Tips from the experts: How to waste a lot of time on this assignment

Linked Lists. What is a Linked List?

MITOCW watch?v=hverxup4cfg

Garbage Collection (1)

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

Introduction to Game Programming Lesson 4 Lecture Notes

The Stack, Free Store, and Global Namespace

Week 12: Priority queues Heaps and heap operations

The Java Type System (continued)

Casting in C++ (intermediate level)

JAVA MOCK TEST JAVA MOCK TEST II

It Might Be Valid, But It's Still Wrong Paul Maskens and Andy Kramek

Supporting Class / C++ Lecture Notes

Tips from the experts: How to waste a lot of time on this assignment

There are functions to handle strings, so we will see the notion of functions itself in little a detail later. (Refer Slide Time: 00:12)


MITOCW watch?v=rvrkt-jxvko

MITOCW MIT6_01SC_rec2_300k.mp4

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Week 7 Prolog overview

MITOCW MIT6_172_F10_lec18_300k-mp4

CSE : Python Programming

Tips from the experts: How to waste a lot of time on this assignment

Early programming languages ca. 1960

What's that? Why? Is one "better" than the other? Terminology. Comparison. Loop testing. Some experts (e.g. Pezze & Young) call it structural testing

Slide 1 CS 170 Java Programming 1

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=4dj1oguwtem

Contents. What's New. Upcoming new version. Newsletter #43 (Aug 6, 2017) A couple quick reminders:

Why do we have to know all that? The stored program concept (the procedural paradigm) Memory

6.034 Artificial Intelligence, Fall 2006 Prof. Patrick H. Winston. Problem Set 1

Q &A on Entity Relationship Diagrams. What is the Point? 1 Q&A

While you can always enter data directly into database tables, you might find it easier to use

6.001 Notes: Section 8.1

COMP-202 Unit 7: More Advanced OOP. CONTENTS: ArrayList HashSet (Optional) HashMap (Optional)

Blitz2D Newbies: Definitive Guide to Types by MutteringGoblin

IP subnetting made easy

Shared Variables and Interference

Chapter 10 Recursion

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

MITOCW watch?v=9h6muyzjms0

05. SINGLETON PATTERN. One of a Kind Objects

The following content is provided under a Creative Commons license. Your support

The. dark side of JAVA. Java bien, j'espère? For what?

Ten Great Reasons to Learn SAS Software's SQL Procedure

Data Structures. Topic #6

Designing for the Cloud

Who am I? I m a python developer who has been working on OpenStack since I currently work for Aptira, who do OpenStack, SDN, and orchestration

COMP19612 exam performance feedback 2014


Shared Variables and Interference

CSE143 Notes for Monday, 7/06/15

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so!

Designing a Database -- Understanding Relational Design

Digital Marketing Manager, Marketing Manager, Agency Owner. Bachelors in Marketing, Advertising, Communications, or equivalent experience

MITOCW ocw f99-lec07_300k

02. OBSERVER PATTERN. Keep your Objects in the know. Don t miss out when something interesting happens

A lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.

The following content is provided under a Creative Commons license. Your support

Part 3. Why do we need both of them? The object-oriented programming paradigm (OOP) Two kinds of object. Important Special Kinds of Member Function

We'll dive right in with an example linked list. Our list will hold the values 1, 2, and 3.!

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Instructor: Craig Duckett. Lecture 03: Tuesday, April 3, 2018 SQL Sorting, Aggregates and Joining Tables

Super-Classes and sub-classes

Read & Download (PDF Kindle) Data Structures And Other Objects Using Java (4th Edition)

The following content is provided under a Creative Commons license. Your support

Post Experiment Interview Questions

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: So far in this course we've been talking a lot about data abstraction. And remember the idea is that

The following content is provided under a Creative Commons license. Your support

5.6.1 The Special Variable this

CS313D: ADVANCED PROGRAMMING LANGUAGE

Staff Intranet Survey Results

Taking Control of Your . Terry Stewart Lowell Williamson AHS Computing Monday, March 20, 2006

Questions. Question Group Welcome to the CROWNWeb Facility Quiz! If you require a screen reader compatible PDF of this quiz,

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Google Docs Website (Sign in or create an account):

The following content is provided under a Creative Commons license. Your support

COMP-202 Unit 4: Programming with Iterations

CS313D: ADVANCED PROGRAMMING LANGUAGE

Transcription:

Week 11: Case study: Designing, building, & testing a Person class Background for the Project Needed in many applications Is it possible? practical? Background Many applications deal with records representing individual people; For example: Personnel systems (Employee) Medical systems (Patient) Academic systems (Student) Library systems (Author) Billing systems (Customer) COMP 170 -- Spring, 2014 Mr Weisert Question Is it possible to define a Person class that will support all those application systems? If so, is it desirable? worth doing? Some experts say: No The needs of each application area are unique You'll just distort the application if you try Others say: Of course Otherwise what good is OOP? Can we exploit inheritance? Person Employee Student Author Patient Customer An Employee is a Person, etc COMP 170, Spring, 2014 1-4 copyright Information Disciiplines, Inc

Obstacles to inheritance Suppose the same Person is both a Student and an Employee Then we'd have two objects Would they be equal? Should they be? How would we specify accessibility? Number of dependents should be public for an Employee, But none of anyone's business for a Customer Those "subclasses" aren't really special kinds of Person They're roles that a Person may play A role can be another kind of object Relationship between Role and Person Natural language (esp English) is misleading It sounds reasonable to say that a Student is a Person But actually: A Person plays a Role (maybe more than one) or A Role is assigned to a Person or vice-versa In OOP those are best represented by a has-a (membership) relationship, even though that departs from common usage Breakthrough! Now we can focus on designing a Person class without having to be concerned about roles A Person object should represent properties that are common to all Persons and are relatively stable What are those properties Basic Person properties Permanent properties dateofbirth name sex Stable properties maritalstatus citizenship Transient properties mailingaddress telephonenumber What else? Change is extremely rare Change is infrequent Change may be frequent COMP 170, Spring, 2014 5-8 copyright Information Disciiplines, Inc

Let's focus on the permanent properties The other properties can be delegated to subclasses role classes databases Another hierarchical issue Should we be concerned about this? Person A general Person class can be useful in all applications RealPerson FictionalCharacter LivingPerson DeceasedPerson Let's focus on RealPerson Every LivingPerson eventually becomes a DeceasedPerson So let's not bother with a cumbersome subclass arrangement Just include a dateofdeath field (null for a LivingPerson) The basic Person class Member data items name dateofbirth dateofdeath sex Questions: What's missing? What data type is each member? COMP 170, Spring, 2014 9-12 copyright Information Disciiplines, Inc

The identity problem Suppose we have persona name ="George Jefferson" sex = male dateofbirth = June 14, 1964 citizenship = USA personb name ="George Jefferson" sex = male dateofbirth = June 14, 1964 citizenship = USA What should personaequals(personb) return? The identifier problem The Boolean equals predicate (Java) or the == operator (C++, C#) must return: true, or false It may not return maybe, or probably Therefore each Person object must have a unique identifier Who assigns them? What's their scope? Identifier Many organizations assign their own, often specific to an application: customer number student number But we still can't tell if a student and a customer are the same person In the United States the social security number (SSN) is the only universal ID It's not supposed to be used for other purposes But everyone does, anyway And you have to apply for one So let's assume: A Person object contains an ID field The ID can be anything, as long as it's unique within the scope of the applications that encounter it Some versions may allow two ID fields An interim one, if the permanent one is unknown at the time the object is first created A permanent one, once we know it COMP 170, Spring, 2014 13-16 copyright Information Disciiplines, Inc

A Person class (rough version) public class Person {???? ID;???? name;???? dateofbirth;???? dateofdeath;???? sex; // Constructors // Accessors // Relational operators etc } What are the missing type codes? A naive version public class Person { long ID; String name; Date dateofbirth; Date dateofdeath; boolean sex; // Constructors // Accessors // Relational operators } What's wrong with that? We're trying to use the object-oriented paradigm public class Person {???? ID;???? name;???? dateofbirth;???? dateofdeath;???? sex; // Constructors // Accessors // Relational operators } Which of those members should be objects? Consider a Person's name What components does it have? What format is it in? English (first middle last) Directory (last, first middle) Other How long may it be? Will it fit on a mailing label? Can a raw String satisfy those criteria? Can a Person's name appear elsewhere (not in a Person object)? Examples? COMP 170, Spring, 2014 17-20 copyright Information Disciiplines, Inc

Conclusion We need a PersonName class in order to: standardize and enforce internal representation facilitate data entry and retrieval It must be a top level class, independent of Person Then PersonName objects can appear in contexts other than member of a Person object, eg in a directory listing or on a mailing label What about Sex? or Gender Three possible values: male female unknown That rules out boolean! What about an integer (0, 1, 2)? a single character (M, F, U)? Must it be standard for an organization? within a single application system? throughout the Java or C# world? Another class? It looks as if we'll need another class for Sex (or Gender) Since it has only three possible values and they're usually immutable, we should consider the enum* facility * Useful for defining discrete data, but not yet covered in our draft textbook Are we done yet? What about the identifier field? We tentatively chose long, but some identifiers contain non-numeric characters We can use a String, but then there's no central format control or enforcement So we need a PersonID class Aren 't we proliferating too many classes? No, that's what OOP is about COMP 170, Spring, 2014 21-24 copyright Information Disciiplines, Inc

An improved version public class Person { PersonID ID; PersonName name; Date dateofbirth; Date Sex dateofdeath; sex; // Constructors // Accessors // Relational operators } We;ve got work to do developing those lower-level classes More bad news for Java programmers! Date and Calendar are among the few numeric classes in the standard Java library We'd like to use them if we can But those are among the worst designed components of the standard Java library! They're extremely awkward, inflexible, and error prone In what ways? In any application where date manipulation and calculation are important, therefore, we prefer to use our own Date class Is C# any better? The bottom line (work plan) We need to develop (design, code, and test) classes, probably in bottom-up sequence PersonID PersonName Date Sex and finally Person Recommended activity Some of the options in our class project call for developing parts or all of a Person class You may also need lower level class definitions for some of the member data Think about how you would approach validating the whole construct Isn't that an awful lot of work? Yes, but all of those classes are potentially reusable That justifies the investment COMP 170, Spring, 2014 25-28 copyright Information Disciiplines, Inc

Strategy for the project Our goal is more to give students an appreciation of how the object-oriented paradigm can help simplify a complex program The good news: We don't expect a fully featured, fully operational production-quality component If you suspect that some result or technique is possible in OOP but can't find out exactly how to implement it, then sketch it and describe what you were trying to accomplish and why it would have been desirable But do make an effort to get something working, and don't violate any important principles COMP 170, Spring, 2014 29-32 copyright Information Disciiplines, Inc