CSC7322: Object Oriented Development. J Paul Gibson, A207.
|
|
- Wilfrid Powers
- 6 years ago
- Views:
Transcription
1 CSC7322: Object Oriented Development J Paul Gibson, A207 paul.gibson@telecom-sudparis.eu Design (In Java) /~gibson/teaching/csc7322/l3-design(in Java).pdf 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.1
2 DISCUSSION: What is (software) design? There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies. C.A.R. Hoare 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.2
3 Some reading material on design (in general) Notes on structured programming. Dijkstra, E.W., On the criteria to be used in decomposing systems into modules, Parnas, David Lorge, 1972 A guided tour of program design methodologies, Bergland, Glenn D., Foundations for the Study of Software Architecture, Dewayne E. Perry and Alexander L. Wolf, 1992 The pragmatics of model-driven development, Selic, Bran Domain-Driven Design: Tackling Complexity in the Heart of Software, Eric Evans, : J Paul Gibson TSP: Object Oriented Development CSC7322/Design.3
4 Design: the bridge between the problem and the solution Discussion: How often does software fail because the design bridge collapses? 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.4
5 Good design is all about experience: Recognising a problem s structure and knowing about alternative solutions (designs) to meeting the requirements of the problem Knowing about implementation issues specific to potential implementation languages/architectures Good judgement is the result of experience Experience is the result of bad judgement. Fred Brooks Realising that there is often not a perfect fit between the design and the target implementation language/architecture Being able to adapt the design to the language and/or adapt the language to the design Note: in OO we may consider the library to be part of the language Let us return to the Dice problem with this in mind. 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.5
6 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.6
7 public interface DiceSpecification extends HasInvariant{ * The minimum number of sides for a Dice as specified in the requirements<br> final static int MINIMUM_numberOfSides = 3; * The maximum number of sides for a Dice as specified in the requirements final static int MAXIMIM_numberOfSides = 36; * The default number of sides for a Dice as specified in the requirements final static int DEFAULT_numberOfSides = 6; 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.7
8 * True if the <code> MAXIMIM_numberOfSides </code>, <code>minimum_numberofsides</code> and * <code> DEFAULT_numberOfSides </code> values for the number of sides of the Dice * are coherent/valid, * otherwise false DiceSpecification#invariant() boolean INVARIANT_OF_CLASS = ( MAXIMIM_numberOfSides >= MINIMUM_numberOfSides && MINIMUM_numberOfSides >0 && DEFAULT_numberOfSides >= MINIMUM_numberOfSides && DEFAULT_numberOfSides <= MAXIMIM_numberOfSides); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.8
9 * Check that the Dice object is in a safe (meaningful) state * true if * <ul> * <li> <ul><li> once the Dice is rolled, the last roll is within range * 1... <code> NUMBEROFSIDES </code></li>, or * <li> if the Dice is yet to be rolled then the last roll value is zero, </li> * </ul> and </li> * <li> the <code> numberofrolls</code> is non-negative, and * </li><li> the number of sides of dice is within range * <code> MINIMUM_numberOfSides </code>... <code> MAXIMUM_numberOfSides</code> * </li> * </ul> * otherwise false * DiceSpecification#INVARIANT_OF_CLASS boolean invariant(); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.9
10 * Getter method for <code> NUMBEROFSIDES</code> * the number of sides of the Dice int numberofsides(); * Getter method for <code> numberofrolls</code> * the number of times the Dice has been rolled since it was constructed int numberofrolls(); * Getter method for reading the value of the <code> lastroll </code><br> * the lastroll value int lastroll (); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.10
11 * Updates the last roll to a random value between 1 and the number of sides, * and increments the roll count. * InvariantBroken if Dice is no longer in a safe state void roll() throws InvariantBroken; 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.11
12 The current state of the Dice as a String<br> * The format to be followed is, eg:<br> * <pre> 6-sided Dice - lastroll = 1. (Total number of rolls = 10) * </pre> public String tostring(); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.12
13 thing is the Object to test for equality true if * <ul> * <li> the two objects reference the same address, or * <li> the thing is a Dice and there is equality on * <code> lastroll</code> and <code> NUMBEROFSIDES</code> fields * </ul> * otherwise false public boolean equals(object thing); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.13
14 thing is the Object to test for equality true if * <ul> * <li> the two objects reference the same address, or * <li> the thing is a Dice and there is equality on * <code> lastroll</code> and <code> NUMBEROFSIDES</code> fields * </ul> * otherwise false public boolean equals(object thing); NOTE: Don t forget to over-ride the hashcode method If two objects are equal by equals() method then the result returned by the hashcode() method must be same. Multiple invocations on same object (that doesnt change state) must return the same result during a single execution; but can differ between executions (!) 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.14
15 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.15
16 public abstract class DiceAbstraction implements DiceSpecification{ public boolean equals( Object thing){ if (thing ==null) return false; if ( this == thing) return true; if (! (thing instanceof DiceAbstraction)) return false; DiceAbstraction that = (DiceAbstraction) thing; return ( (this.lastroll() == that.lastroll()) && (this.numberofsides() == that.numberofsides()) ); public String tostring(){ String str =""; str = str+ numberofsides()+"-sided Dice - lastroll = "+lastroll()+ ". (Total number of rolls = "+numberofrolls()+")"; return str; 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.16
17 * Algorithm taken from Josh Bloch's "Effective Java", using primes 37 and 41 * <ul> * <li> initialise with prime = 37</li> * <li> for each field tested in {@link DiceAbstraction#equals increase * iteratively with another prime multiplier: * hash = 41 * hash + field_integer_value </li> * </ul> * public int hashcode(){ int hash = 37; // start with a prime hash = 41 * hash + lastroll(); // iteratively increase with another prime multiplier hash = 41 * hash + numberofsides(); return hash; 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.17
18 public boolean invariant(){ return (( (numberofrolls() == 0 && lastroll() == 0 ) (numberofrolls() > 0 && lastroll()>0 && lastroll()<=numberofsides() ) )&& (numberofsides()>=minimum_numberofsides) && (numberofsides() <= MAXIMIM_numberOfSides) ); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.18
19 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.19
20 public class Dice extends DiceAbstraction implements DiceSpecification{ // The javadocs are in the code removed here for easier presentation public final int NUMBEROFSIDES; protected Random rng = new Random(); protected static int numberofdie = 0; protected int numberofrolls = 0; protected int lastroll = 0; public boolean invariant(){ return super.invariant() && rng!=null; // We saw constructors in previous lecture 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.20
21 public int lastroll (){ return lastroll; public int numberofsides(){ return NUMBEROFSIDES; public int numberofrolls(){ return numberofrolls; * Getter method for the static <code> numberofdie </code> the number of Die that have been constructed public static int numberofdie(){ return numberofdie; QUESTION : Why is the static method not specified in the interface or abstract class? 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.21
22 * Setter method for the random number generator local to the dice<br> * * Tested by {@link JUnit_DiceTest#testSetRNGException, which shows that * we do not need to check invariant as any invalid change to rng is caught * rng is the new random number generator to be used when rolling the dice IllegalArgumentException if argument <code> rng </code> is <code>null</code> public void setrng( Random rng) throws IllegalArgumentException{ if (rng==null) throw (new IllegalArgumentException("Cannot set rng to null")); this.rng = rng; // if (!invariant()) throw (new InvariantBroken("Dice is no longer in a safe state")); * Tested by {@link JUnit_DiceAbstractionTest#testRoll, which guarantees that the Dice is * constructed in a safe state as specified by {@link Dice#invariant. * public void roll() throws InvariantBroken{ lastroll = rng.nextint(numberofsides)+1; numberofrolls++; // if (!invariant()) throw (new InvariantBroken("Dice is no longer in a safe state")); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.22
23 @Before public abstract void setup() throws public abstract void teardown() throws Exception; 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.23
24 public class JUnit_DiceTest extends public void setup() throws Exception { dicedefault = new Dice(); dicenondefaultok = new Dice((Dice.MAXIMIM_numberOfSides + Dice.MINIMUM_numberOfSides)/2); dicenondefaultko = new Dice(Dice.MAXIMIM_numberOfSides + 1); dicerolledtwice = new Dice(); dicerolledtwice.roll(); dicerolledtwice.roll(); dicecopyrolledtwice = new Dice ( (Dice) dicerolledtwice); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.24
25 * test exception in = IllegalArgumentException.class) public void testsetrngexception() { ((Dice) dicedefault).setrng(null); * test {@link Dice#numberOfDie() by creating 10 new die and checking public void testnumberofdie() { int countnumberofdie = Dice.numberOfDie(); final int NUMBER_OF_DIE_TO_CONSTRUCT = 10; for (int i=0; i<number_of_die_to_construct; i++) new Dice(); Assert.assertEquals(countNumberOfDie+NUMBER_OF_DIE_TO_CONSTRUCT, Dice.numberOfDie()); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.25
26 WARNING: All green does not always mean that all is well! DISCUSSION: Why not? 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.26
27 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.27
28 public class Random_DiceTest { protected static Dice dice = new Dice(); public static void main(string[] args) { * The number of rolls in our simulation final int NUMBER_OF_TEST_ROLLS = 6; Random rng = SeedRNGCommandLine.getRandom(args); System.out.println(DateHeader.dateString()); System.out.println(dice); dice.setrng(rng); System.out.println("Rolling "+NUMBER_OF_TEST_ROLLS+ " times"); for (int i =1; i<=number_of_test_rolls;i++){ dice.roll(); System.out.println(i+". Roll = " +dice.lastroll() ); System.out.println(dice); 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.28
29 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.29
30 TO DO: Create a new class which adds statistics to the dice This class should add functionality to store the roll frequencies. You should implement a validation test (as well as running unit tests) as below: NOTE: Don t forget to run regression tests 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.30
31 TO DO: Implement 2 different designs //using inheritance public class DiceWithStatistics1 extends Dice implements DiceWithStatisticsSpecification{ //using composition public class DiceWithStatistics2 implements DiceWithStatisticsSpecification{ protected Dice dice; 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.31
32 TO DO: Create 2 different terminal/console views The frequencies can either be displayed vertically or horizontally. If the frequency values are bigger than the height/width of the screen then you should scale them in order to occupy as much of the screen as possible. The screen size should be stored in constant variables HEIGHT and WIDTH. 1 ******** 2 ****** 3 *** 4 **** 5 ****** 6 ** 7 *** 8 ** 9 ***** ***** 12 ** 13 ******** 14 ***** 15 ********* * * * * * * * * * * * * * * * * * * * * ** * * * ** * * * ** * * * *** ** ** * * *** ** ** * * *** ***** * * * *** ***** * * * *** ********* ***** ********* ***** ********* ***** ********* ***** ********* ***** DISCUSSION: How to best include these views in the design? 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.32
33 The consequences of the initial design decision Choosing to implement a DiceWithStatistics as a subclass of Dice is a design decision that may have consequencies on later stages of the development. The alternative re-use mechanism was to design a DiceWithStatistics class/object to have a Dice component class/object. This also may have consequencies on later stages of the development DISCUSSION: What are the possible consequences (positive and negative)? CLUE: You may have seen them when we considered the different views OBSERVERS: We may wish to create different views that automatically update when the state of the models changes 2013: J Paul Gibson TSP: Object Oriented Development CSC7322/Design.33
Fundamental Concepts (In Java)
CSC7322: Object Oriented Development J Paul Gibson, A207 paul.gibson@telecom-sudparis.eu http://www-public.telecom-sudparis.eu/~gibson/teaching/csc7322/ Fundamental Concepts (In Java) /~gibson/teaching/csc7322/l2-fundamentalconcepts.pdf
More informationTO DO: Create a new class which adds statistics to the dice. NOTE: Don t forget to run regression tests
TO DO: Create a new class which adds statistics to the dice This class should add functionality to store the roll frequencies. You should implement a validation test (as well as running unit tests) as
More informationInheritance (Part 5) Odds and ends
Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there
More informationpublic static boolean isoutside(int min, int max, int value)
See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static
More informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More informationG51PGP Programming Paradigms. Lecture OO-4 Aggregation
G51PGP Programming Paradigms Lecture OO-4 Aggregation 1 The story so far We saw that C code can be converted into Java code Note real object oriented code though Hopefully shows you how much you already
More informationCSE wi Midterm Exam 2/8/18. Name UW ID #
Name UW ID # There are 11 questions worth a total of 120 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationSession 04 - Object-Oriented Programming 1 Self-Assessment
UC3M Alberto Cortés Martín Systems Programming, 2014-2015 version: 2015-02-06 Session 04 - Object-Oriented Programming 1 Self-Assessment Exercise 1 Rectangles Part 1.A Write a class called Rectangle1 that
More informationCMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.
CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object
More informationInheritance. Notes Chapter 6 and AJ Chapters 7 and 8
Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg
More informationCOMP200 - Object Oriented Programming: Test One Duration - 60 minutes
COMP200 - Object Oriented Programming: Test One Duration - 60 minutes Study the following class and answer the questions that follow: package shapes3d; public class Circular3DShape { private double radius;
More informationCSE wi Midterm Exam 2/8/18 Sample Solution
Remember: For all of the questions involving proofs, assertions, invariants, and so forth, you should assume that all numeric quantities are unbounded integers (i.e., overflow can not happen) and that
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationClasses Classes 2 / 36
Classes 1 / 36 Classes Classes 2 / 36 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays
More informationCSE331 Winter 2014, Midterm Examination February 12, 2014
CSE331 Winter 2014, Midterm Examination February 12, 2014 Please do not turn the page until 10:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 11:20. There are 100 points
More informationJava Classes, Inheritance, and Interfaces
Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationFor this section, we will implement a class with only non-static features, that represents a rectangle
For this section, we will implement a class with only non-static features, that represents a rectangle 2 As in the last lecture, the class declaration starts by specifying the class name public class Rectangle
More informationAbstract Classes and Interfaces
Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass
More informationClass, Variable, Constructor, Object, Method Questions
Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx
More informationThe class Object. Lecture CS1122 Summer 2008
The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship
More informationCS 61B Discussion 5: Inheritance II Fall 2014
CS 61B Discussion 5: Inheritance II Fall 2014 1 WeirdList Below is a partial solution to the WeirdList problem from homework 3 showing only the most important lines. Part A. Complete the implementation
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationSchool of Informatics, University of Edinburgh
CS1Ah Lecture Note 17 Case Study: Using Arrays This note has three main aims: 1. To illustrate the use of arrays introduced in Lecture Note 16, on a slightly larger example. 2. To introduce the idea of
More informationReview: Array Initializer Lists
More on Arrays Review of Arrays of ints, doubles, chars Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 7.2 Reading for this lecture: L&L 7.3 7.7,
More informationArrays. Chapter Arrays What is an Array?
Chapter 8 Arrays 81 Arrays 811 What is an Array? To motivate why we might be interested in using arrays, let us implement an app that creates a collection of doubles We will keep track of the number of
More informationCS159. Nathan Sprague. September 30, 2015
CS159 Nathan Sprague September 30, 2015 Testing Happens at Multiple Levels Unit Testing - Test individual classes in isolation. Focus is on making sure that each method works according to specification.
More informationExceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws
Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws 1 By the end of this lecture, you will be able to differentiate between errors, exceptions,
More informationCanonical Form. No argument constructor Object Equality String representation Cloning Serialization Hashing. Software Engineering
CSC40232: SOFTWARE ENGINEERING Professor: Jane Cleland Huang Canonical Form sarec.nd.edu/courses/se2017 Department of Computer Science and Engineering Canonical Form Canonical form is a practice that conforms
More informationDefensive Programming
Defensive Programming Software Engineering CITS1220 Based on the Java1200 Lecture notes by Gordon Royle Lecture Outline Why program defensively? Encapsulation Access Restrictions Documentation Unchecked
More informationJava Magistère BFA
Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt
More informationJava Fundamentals (II)
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class
More informationGarbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }
Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;
More informationOne of these "compartments" is more correctly referred to as an element of the array
An array is a special type of variable in that it can contain many values If a standard variable is like a box, think of an array as being like a box with compartments: One of these "compartments" is more
More informationClasses Classes 2 / 35
Classes 1 / 35 Classes Classes 2 / 35 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays
More informationpublic static void negate2(list<integer> t)
See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static
More informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationCS/ENGRD 2110 FALL2017. Lecture 4: The class hierarchy; static components
1 CS/ENGRD 2110 FALL2017 Lecture 4: The class hierarchy; static components http://cs.cornell.edu/courses/cs2110 Announcements 2 A0, HW1 due tonight Next week s recitation: loop invariants for ( ) { You
More informationDesign Patterns Revisited
CSC 7322 : Object Oriented Development J Paul Gibson, A207 paul.gibson@int-edu.eu http://www-public.it-sudparis.eu/~gibson/teaching/csc7322/ Design Patterns Revisited /~gibson/teaching/csc7322/l13-designpatterns-2.pdf
More informationCOMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others
COMP-202 Recursion Recursion Recursive Definitions Run-time Stacks Recursive Programming Recursion vs. Iteration Indirect Recursion Lecture Outline 2 Recursive Definitions (1) A recursive definition is
More informationToday. Book-keeping. Inheritance. Subscribe to sipb-iap-java-students. Slides and code at Interfaces.
Today Book-keeping Inheritance Subscribe to sipb-iap-java-students Interfaces Slides and code at http://sipb.mit.edu/iap/java/ The Object class Problem set 1 released 1 2 So far... Inheritance Basic objects,
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationLecture 2: Java & Javadoc
Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block
More informationChair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 10
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Exercise Session 10 Today s Exercise Session Pattern of the Day Proxy Quizzes 2 Proxy Pattern Structural
More informationSubclassing for ADTs Implementation
Object-Oriented Design Lecture 8 CS 3500 Fall 2009 (Pucella) Tuesday, Oct 6, 2009 Subclassing for ADTs Implementation An interesting use of subclassing is to implement some forms of ADTs more cleanly,
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming
More informationLecture 20: Implementation () / 33
Lecture 20: Implementation 15.07.2013 () 15.07.2013 1 / 33 Contents Implementation Implementation Principles Example: Eight Queens by Refinement () 15.07.2013 2 / 33 Implementation Input: software architecture,
More informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationCMSC 132: Object-Oriented Programming II. Effective Java. Department of Computer Science University of Maryland, College Park
CMSC 132: Object-Oriented Programming II Effective Java Department of Computer Science University of Maryland, College Park Effective Java Textbook Title Effective Java, Second Edition Author Joshua Bloch
More informationJava Persistence API (JPA) Entities
Java Persistence API (JPA) Entities JPA Entities JPA Entity is simple (POJO) Java class satisfying requirements of JavaBeans specification Setters and getters must conform to strict form Every entity must
More informationCode Reuse: Inheritance
Object-Oriented Design Lecture 14 CSU 370 Fall 2008 (Pucella) Tuesday, Nov 4, 2008 Code Reuse: Inheritance Recall the Point ADT we talked about in Lecture 8: The Point ADT: public static Point make (int,
More informationJava Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar
Java Classes Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More information11 HashMap: Overriding equals ; JUnit; Vistors
11 HashMap: Overriding equals ; JUnit; Vistors Goals In this lab we will first learn how to define the equals method, as well as how to use the HashMap data structure defined in the Java Collections Frameworks.
More information(a) Write the signature (visibility, name, parameters, types) of the method(s) required
1. (6 pts) Is the final comprehensive? 1 2. (6 pts) Java has interfaces Comparable and Comparator. As discussed in class, what is the main advantage of Comparator? 3. (6 pts) We can use a comparator in
More informationPrinciples of Object Oriented Programming. Lecture 4
Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data
More informationDocumen(ng code, Javadoc, Defensive Programming, Asserts, Excep(ons & Try/Catch
Documen(ng code, Javadoc, Defensive Programming, Asserts, Excep(ons & Try/Catch 1 Most important reason to comment A) To summarize the code B) To explain how the code works C) To mark loca(ons that need
More informationWe would like guidance on how to write our programs beyond simply knowing correlations between inputs and outputs.
Chapter 3 Correctness One of the most appealing aspects of computer programs is that they have a close connection to mathematics, in particular, logic. We use these connections implicitly every day when
More informationMethods Common to all Classes
Methods Common to all Classes 9-2-2013 OOP concepts Overloading vs. Overriding Use of this. and this(); use of super. and super() Methods common to all classes: tostring(), equals(), hashcode() HW#1 posted;
More informationPolymorphism. return a.doublevalue() + b.doublevalue();
Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationINSTRUCTIONS TO CANDIDATES
NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING FINAL ASSESSMENT FOR Semester 1 AY2017/2018 CS2030 Programming Methodology II November 2017 Time Allowed 2 Hours INSTRUCTIONS TO CANDIDATES 1. This
More information16-Dec-10. Consider the following method:
Boaz Kantor Introduction to Computer Science IDC Herzliya Exception is a class. Java comes with many, we can write our own. The Exception objects, along with some Java-specific structures, allow us to
More informationSimple Component Writer's Guide
Simple Component Writer's Guide Note that most of the following also applies to writing ordinary libraries for Simple. The preferred language to write Simple components is Java, although it should be possible
More informationCSE 331 Midterm Exam Sample Solution 2/18/15
Question 1. (10 points) (Forward reasoning) Using forward reasoning, write an assertion in each blank space indicating what is known about the program state at that point, given the precondition and the
More informationReview Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous
Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:
More informationCSE 331 Spring 2018 Midterm
CSE 331 Spring 2018 Midterm Name There are 8 questions worth a total of 93 points. Please budget your time so that you get as many points as possible. We have done our best to make a test that folks can
More informationCOMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016 Announcements Final is scheduled for Apr 21, 2pm 5pm GYM FIELD HOUSE Rows 1-21 Please submit course evaluations!
More information! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like
Indefinite loops while loop! indefinite loop: A loop where it is not obvious in advance how many times it will execute.! We often use language like " "Keep looping as long as or while this condition is
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming
More informationObject Oriented Programming
Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented
More informationDesigning and Implementing Classes Topic 6
Designing and Implementing Classes Topic 6 Don't know much geography Don't know much trigonometry Don't know much about algebra Don't know what a slide rule is for -Sam Cooke AP Computer Science Designing
More informationBinghamton University. CS-140 Fall Chapter 9. Inheritance
Chapter 9 Inheritance 1 Shapes Created class Point for (x,y) points Created classes: Rectangle, Circle, RightTriangle All have llc field All have dimensions, but different for each shape All have identical
More informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar 2018
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationPractice exam for CMSC131-04, Fall 2017
Practice exam for CMSC131-04, Fall 2017 Q1 makepalindrome - Relevant topics: arrays, loops Write a method makepalidrome that takes an int array, return a new int array that contains the values from the
More informationCS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016
Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016 There are 7 problems on the exam, with 50 points total available. There are 8 pages to the exam (4 pages double-sided),
More informationThreads(in Java) CSC J Paul Gibson, D311.
CSC 7203 J Paul Gibson, D311 paul.gibson@telecom-sudparis.eu http://www-public.it-sudparis.eu/~gibson/teaching/csc7203/ Threads(in Java) /~gibson/teaching/csc7203/csc7203-advancedoo-l6-threads.pdf 1 Processes
More informationCOE318 Lecture Notes Week 10 (Nov 7, 2011)
COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:
More informationSuper-Classes and sub-classes
Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationCIT 590 Homework 10 Battleship
CIT 590 Homework 10 Battleship Purposes of this assignment: To give you more experience with classes and inheritance General Idea of the Assignment Once again, this assignment is based on a game, since
More informationObject Oriented Programming Exception Handling
Object Oriented Programming Exception Handling Budditha Hettige Department of Computer Science Programming Errors Types Syntax Errors Logical Errors Runtime Errors Syntax Errors Error in the syntax of
More informationTopic 3 Encapsulation - Implementing Classes
Topic 3 Encapsulation - Implementing Classes And so, from Europe, we get things such as... object-oriented analysis and design (a clever way of breaking up software programming instructions and data into
More informationSoftware Development (cs2500)
Software Development (cs2500) Lecture 31: Abstract Classes and Methods M.R.C. van Dongen January 12, 2011 Contents 1 Outline 1 2 Abstract Classes 1 3 Abstract Methods 3 4 The Object Class 4 4.1 Overriding
More informationLecture 14 Summary 3/9/2009. By the end of this lecture, you will be able to differentiate between errors, exceptions, and runtime exceptions.
Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions...catch...finally throw and throws By the end of this lecture, you will be able to differentiate between errors, exceptions, and
More informationCOMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed
1 1 COMP200 INHERITANCE OOP using Java, from slides by Shayan Javed 2 Inheritance Derive new classes (subclass) from existing ones (superclass). Only the Object class (java.lang) has no superclass Every
More informationC12a: The Object Superclass and Selected Methods
CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and
More informationDomain-Driven Design Activity
Domain-Driven Design Activity SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Entities and Value Objects are special types of objects
More informationMSc/ICY Software Workshop Exception Handling, Assertions Scanner, Patterns File Input/Output
MSc/ICY Software Workshop Exception Handling, Assertions Scanner, Patterns File Input/Output Manfred Kerber www.cs.bham.ac.uk/~mmk 21 October 2015 1 / 18 Manfred Kerber Classes and Objects The information
More informationSoftware Construction
Lecture 5: Robustness, Exceptions Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering & Technology
More informationCS 139 Practice Midterm Questions #2
CS 139 Practice Midterm Questions #2 Spring 2016 Name: 1. Write Java statements to accomplish each of the following. (a) Declares numbers to be an array of int s. (b) Initializes numbers to contain a reference
More informationCSCI 261 Computer Science II
CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 2 Exception Handling New Topic: Exceptions in Java You should now be familiar with: Advanced object-oriented design -
More informationWhy OO programming? want but aren t. Ø What are its components?
9/21/15 Objec,ves Assign 1 Discussion Object- oriented programming in Java Java Conven,ons: Ø Constructors Ø Default constructors Ø Sta,c methods, variables Ø Inherited methods Ø Class names: begin with
More informationLecture 4: The class hierarchy; static components
1 CS/ENGRD 2110 FALL2017 Lecture 4: The class hierarchy; static components http://cs.cornell.edu/courses/cs2110 Announcements 2 A1 Due Thursday A2 Out Today Where am I? Big ideas so far. 3 Java variables
More informationTicket Machine Project(s)
Ticket Machine Project(s) Understanding the basic contents of classes Produced by: Dr. Siobhán Drohan (based on Chapter 2, Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes,
More information2. [20] Suppose we start declaring a Rectangle class as follows:
1. [8] Create declarations for each of the following. You do not need to provide any constructors or method definitions. (a) The instance variables of a class to hold information on a Minesweeper cell:
More informationDynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable
Hashing Dynamic Dictionaries Operations: create insert find remove max/ min write out in sorted order Only defined for object classes that are Comparable Hash tables Operations: create insert find remove
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationMore about inheritance
Main concepts to be covered More about inheritance Exploring polymorphism method polymorphism static and dynamic type overriding dynamic method lookup protected access 4.1 The inheritance hierarchy Conflicting
More informationObject Oriented Programming
Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented
More information