CS193j, Stanford Handout #10 OOP 3
|
|
|
- Dina Waters
- 10 years ago
- Views:
Transcription
1 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples AbstractCollection class in java libraries Account example below Abstract Method The "abstract" keyword can be added to a method. e.g. public abstract void mustimplement(); // note: no {, no code An abstract method defines the method name and arguments, but there's no method code. Subclasses must provide an implementation. Abstract Class The "abstract" keyword can be applied to a class e.g. public abstract class Account {... A class that has one or more abstract methods is abstract -- it cannot be instantiated. "New" may not be used to create instances of the Abstract class. A class is not abstract if all of the abstract methods of its superclasses have definitions. Abstract Super Class A common superclass for several subclasses. Factor up common behavior Define the methods they all respond to. Methods that subclasses should implement are declared abstract Instances of the subclasses are created, but no instances of the superclass Clever Factoring Style Common Superclass Factor common behavior up into a superclass. The superclass sends itself messages to invoke various parts of its behavior. Special Subclasses Subclasses are as short as possible. Rely on the superclass methods for common behavior. Use overriding of key methods to customize behavior with the minimum of code
2 2 Rely on the "pop-down" behavior -- control pops down to the subclass for overridden behavior, and then returns to the superclass to continue the common code. The java drawing class JComponent is an example of this sort of common superclass with lots of subclasses. Danger: Showing students this sort of example is a little dangerous. The engineering of it is neat and tidy, so it makes the whole concept appealing. However, opportunities for this sort of factoring are rare. Polymorphism Given an array of Account[] -- pointers with the CT type to the superclass Send them messages like, withdraw() -- control pops down to the correct subclass depending on its RT type. Account Example The Account example demonstrates the clever-factoring technique. Consider an object-oriented design for the following problem. You need to store information for bank accounts. For purposes of the problem, assume that you only need to store the current balance, and the total number of transactions for each account. The goal for the problem is to avoid duplicating code between the three types of account. An account needs to respond to the following messages: - constructor(initialbalance) - deposit(amount) - withdraw(amount) - endmonth() Apply the end-of-month charge, print out a summary, zero the transaction count. There are three types of account: Normal: There is a fixed $5.00 fee at the end of the month. Nickle 'n Dime: Each withdrawal generates a $0.50 fee the total fee is charged at the end of the month. The Gambler: A withdrawal returns the requested amount of money, however the amount deducted from the balance is as follows: there is a 0.49 probability that no money will actually be subtracted from the balance. There is a 0.51 probability that twice the amount actually withdrawn will be subtracted. There is no monthly fee. 1. Factoring The point: arrange the three classes in a hierarchy below a common Account class. Factor common behavior up into Account. Mostly the classes use the default behavior. For key behaviors, subclasses override the default behavior e.g. Gambler.withdraw(). This keeps the subclasses very short with most of the code factored up to the superclass. 2. Abstract Methods A method declared "abstract" defines no code. It just defines the prototype, and requires subclasses to provide code. In the code below, the endmonthcharge() method is declared abstract in Account, so the subclasses must provide a definition.
3 3 Account *balance *transactions -deposit -withdraw -endmonth -endmonthcharge (abstract) Fee -endmonthcharge NickleNDime *withdrawcount -withdraw -endmonthcharge Gambler -withdraw -endmonthcharge Account Code // Account.java /* The Account class is an abstract super class with the default characteristics of a bank account. It maintains a balance and a current number of transactions. There are default implementation for deposit(), withdraw(), and endmonth() (prints out the end-month-summary). However the endmonthcharge() method is abstract, and so must be defined by each subclass. This is a classic structure of using clever factoring to pull common behavior up to the superclass. The resulting sublclasses are very thin. */ import java.util.*; public abstract class Account { protected double balance; protected int transactions; // protected = avaiable to subclasses public Account(double balance) { this.balance = balance; transactions = 0; // Withdraws the given amount and counts a transaction public void withdraw(double amt) { balance = balance - amt; transactions++; // Deposits the given amount and counts a transaction public void deposit(double amt) { balance = balance + amt; transactions++; public double getbalance() { return(balance);
4 4 /* Sent to the account at the end of the month so it can settle fees and print a summary. Relies on the endmonthcharge() method for each class to implement its own charge policy. Then does the common account printing and maintenance. */ public void endmonth() { // 1. Pop down to the subclass for their // specific charge policy (abstract method) endmonthcharge(); // 2. now the code common to all classes // Get our RT class name -- just showing off // some of Java's dynamic "reflection" stuff. // (Never use a string like this for switch() logic.) String myclassname = (getclass()).getname(); System.out.println("transactions:" + transactions + "\t balance:" + balance + "\t(" + myclassname + ")"); transactions = 0; /* Applies the end-of-month charge to the account. This is "abstract" so subclasses must override and provide a definition. At run time, this will "pop down" to the subclass definition. */ protected abstract void endmonthcharge(); //---- // Demo Code //---- // Allocate a Random object shared by these static methods private static Random rand = new Random(); // Return a new random account of a random type. private static Account randomaccount() { int pick = rand.nextint(3); Account result = null; switch (pick) { case 0: result = new Gambler(rand.nextInt(100)); break; case 1: result = new NickleNDime(rand.nextInt(100)); break; case 2: result = new Fee(rand.nextInt(100)); break; /**** // Another way to create new instances -- needs a default ctor try { Class gclass = Class.forName("Gambler"); result = (Gambler) gclass.newinstance(); catch (Exception e) {
5 5 e.printstacktrace(); ****/ return(result); private static final int NUM_ACCOUNTS = 20; // Demo polymorphism across Accounts. public static void main(string args[]) { // 1. Build an array of assorted accounts Account[] accounts = new Account[NUM_ACCOUNTS]; // Allocate all the Account objects. for (int i = 0; i<accounts.length; i++) { accounts[i] = Account.randomAccount(); // 2. Simulate a bunch of transactions for (int day = 1; day<=31; day++) { int accountnum = rand.nextint(accounts.length); // choose an account if (rand.nextint(2) == 0) { // do something to that account accounts[accountnum].withdraw(rand.nextint(100) + 1);//Polymorphism Yay! else { accounts[accountnum].deposit(rand.nextint(100) + 1); // 3. Have each account print its state System.out.println("End of month summaries..."); for (int acct = 0; acct<accounts.length; acct++) { accounts[acct].endmonth(); // Polymorphism Yay! // output /* End of month summaries... transactions:1 balance:-1.0 (Fee) transactions:5 balance:-84.0 (NickleNDime) transactions:2 balance:43.5 (NickleNDime) transactions:1 balance:90.0 (NickleNDime) transactions:2 balance:89.0 (Fee) transactions:1 balance:1.0 (Gambler) transactions:1 balance:88.0 (NickleNDime) transactions:1 balance:150.0 (Gambler) transactions:6 balance:-19.5 (NickleNDime) transactions:2 balance:-29.0 (Fee) transactions:4 balance:226.0 (Gambler) transactions:1 balance:86.0 (Gambler) transactions:2 balance:70.0 (Fee) transactions:2 balance:131.5 (NickleNDime) transactions:4 balance:-42.5 (NickleNDime) transactions:2 balance:-20.5 (NickleNDime) transactions:3 balance:85.0 (Fee) transactions:1 balance:-71.0 (Gambler) transactions:2 balance: (Gambler) transactions:2 balance:-48.0 (Fee) */
6 6 /* Things to notice. -Because the Account ctor takes an argument, all the subclasses need a ctor so they can pass the right value up. This chore can be avoided if the superclass has a default ctor. -Suppose we want to forbid negative balance -- all the classes "bottleneck" through withdraw(), so we just need to implement something in that one place. Bottlenecking common code through one place is good. -Note the "polymorphism" of the demo in Account.main(). It can send Account obects deposit(), endmonth(), etc. messages and rely on the receivers to do the right thing. -Suppose we have a "Vegas" behavior where a person withdraws 500, and slightly later deposits(50). Could implement this up in Account.. public void Vegas() { withdraw(500); // go lose 90% of the money deposit(50); Depending on the class of the receiver, it will do the right thing. Exercise: trace the above on a Gambler object -- what is the sequence of methods that execute? */ // Fee.java // An Account where there's a flat $5 fee per month. // Implements endmonth() to get the fee effect. public class Fee extends Account { public final double FEE = 5.00; public Fee(double balance) { super(balance); public void endmonthcharge() { withdraw(fee); // NickleNDime.java // An Acccount subclass where there's a $0.50 fee per withdrawal. // Overrides withdraw() to count the withdrawals and // endmonthcharge() to levy the charge. public class NickleNDime extends Account { public final double WITHDRAW_FEE = 0.50; private int withdrawcount;
7 7 public NickleNDime(double balance) { super(balance); withdrawcount = 0;; public void withdraw(double amount) { super.withdraw(amount); withdrawcount++; public void endmonthcharge() { withdraw(withdrawcount * WITHDRAW_FEE); withdrawcount = 0; // Gambler.java // An Account where sometimes withdrawals deduct 0 // and sometimes they deduct twice the amount. No end of month fee. // Has an empty implementation of endmonthcharge, // and overrides withdraw() to get the interesting effect. public class Gambler extends Account { public final double PAY_ODDS = 0.51; public Gambler(double balance) { super(balance); public void withdraw(double amt) { if (Math.random()<= PAY_ODDS) { super.withdraw(2 * amt); // unlucky else { super.withdraw(0.0); // lucky (still count the transaction) public void endmonthcharge() { // ha ha, we don't get charged anything! 1. Gambler.withdraw() -- super Notice we use super.withdraw() to use our superclass code. Do not repeat code that the superclass can do. Be careful if you find yourself copying code from the superclass and pasting it into the subclass.
8 2. Account.endMonth() -- pop-down Sends itself the endmonthcharge() message -- this pops-down to the implementation in each subclass. 3. Account.main() -- polymorphism Constructs and Account[] array Iterates through, sending the withdraw() message Pops-down to the right implementation of withdraw() depending on the RT type of the receiver 8
9 9 Inheritance Issues... Subclassing Examples Animal : Bird ("bird isa animal") Vehicle : Watercraft : Kayak Collection : Stack Drawable Thing : Drawable Thing which can also be clicked on : Button Airplane : Engine NO ("engine isa airplane"? no) Collection : Int NO Stack : Collection NO (it's backwards) Inheritance vs. Switch Statement If different classes need to behave differently, then have them each implement the behavior and leverage the message/method resolution machinery. Never write code like the following... switch (<type of object being dealt with>) { // probably a bad idea case <a>: <a behavior> break; case <b>: <b behavior> break; case <c>: <c behavior> break; Use the message/method machinery to do the switch for you. Switch logic still makes sense if it makes distinctions on some other run-time state, but if it has something to do with the class of the receiver, then using a method makes much more sense. Inheritance vs. instanceof test As with the switch case above, code that uses instanceof is a little suspect. It can be necessary in some cases though. if (obj instanceof Foo) {... Subclassing Relationship Subclassing is used between classes with significant overlap. Subclassing establishes a significant constraint between the subclass and its superclass the subclass "isa" specialized form of its superclass. The subclass must have every feature of the superclass. It must support every operation of the superclass. As a result, the subclass is capable of fitting in all the contexts where its superclass fits. Subclassing vs. Encapsulation As a practical matter, subclassing often breaks the encapsulation of the superclass. The subclass is very likely to pick up dependencies on the implementation of the superclass. In this way, the super-sub relationship makes the subclass dependent on the implementation details of the superclass.
10 It is possible to keep the super/sub independent from each other, but it takes dedication. In particular, the superclass must declare its ivars private, and the subclass must go through get/set methods, like an ordinary client. The relationship between a subclass and its superclass tends to involve tighter coupling than for a simple client/implementation relationship. Subclass -- With Caution When writing a subclass, realize there are significant couplings with the superclass. You need to understand the superclass so your subclass can fit in to its design. Superclass -- Rare, Deliberate When designing a class, do not include the "someone could subclass off here" feature as an afterthought. In general, you do not need to worry about subclassing -- declare ivars and utility methods private. If you're going to support subclassing, the design, docs, etc. need to intentionally think about that case right from the start. Inheritance Without Perfect Factoring In the classical picture, behavior common to all subclasses is factored up to the common superclass. However, not all cases are that tidy. It may be acceptable to have behaviors that are 75% common up in the superclass, with some if logic to get around the cases that don't fit in. This is where you might use an "if (obj instanceof Subclass) {..." test to change the code path depending on the class of the receiver. This goes against the no-switch rule, but may be reasonable in some cases. Not all problems fit the classic picture -- "it depends" Java "interface" Method Prototypes An interface defines a set of method prototypes. Does not provide code for implementation -- just the prototypes. Can also define final constants. Class implements interface A class that implements an interface must implement all the methods in the interface. The compiler checks this at compile time. A Java class can only have one superclass, but it may implement any number of interfaces. "Responds To" The interface is a "responds to" claim about a set of methods. If a class implements the Foo interface, I know it responds to all the messages in the Foo interface. In this sense, an interface is very similar to a superclass. If an object implements the Foo interface, a pointer to the object may be stored in a Foo variable. (Just like storing a pointer to a Grad object in a Student variable.) Lightweight 10
11 11 Interfaces allow multiple classes to respond to a common set of messages, but without introducing much implementation complexity. Interfaces are lightweight compared to superclasses. This is similar to subclassing, however... Good news: A class an only have one superclass, however it can implement any number of interfaces. Interfaces are a more simple, more lightweight mechanism. Bad news: An interface only gives the message prototype, no implementation code. The class must implement the method from scratch. vs. Multiple Inheritance C++ multiple inheritance is more capable -- multiple superclasses -- but it introduces a lot of compiler and language complexity, so maybe it is not worth it. Interfaces provide 80% of the benefit for 10% of the complexity. e.g. Moodable Interface Suppose you are implementing some sort simulation, and there are all sorts of different objects in the program with different superclasses. However, you want to add a "mood ring" feature, where we can query the current color mood out an object. Some classes will support mood and some won't We define the Moodable interface -- any class that wants to support the Mood feature, implements the Moodable interface public interface Moodable { public Color getmood(); // interface defines getmood() prototype but no code If a class claims to implement the Moodable interface, the compiler will enforce that the class must respond to the getcolor(); message. Student implements Moodable Here is what the Student class might look like, extended to implement the Moodable interface. The class must provide code for all the messages mentioned in the interface, in this case just getmood(). public class Student implements Moodable { public Color getmood() { if (getstress()>100) return(color.red); else return(color.green); // rest of Student class stuff as before... Client Side Moodable Moodable is like an additional superclass of Student. It is possible to store a pointer to a Student in a pointer of type Moodable. The type system essentially wants to enforce the "responds to" rules. It's ok to store a pointer to a Student in a Moodable, since Student responds to getmood().
12 12 So could say... Student s = new Student(10); Moodable m = s; m.getmood(); // Moodable can point to a Student // this works
Chapter 13 - Inheritance
Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package
D06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch13 Inheritance PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for accompanying
ICOM 4015: Advanced Programming
ICOM 4015: Advanced Programming Lecture 10 Reading: Chapter Ten: Inheritance Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 10 Inheritance Chapter Goals To learn about inheritance To
Inheritance, overloading and overriding
Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class
3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.
Industrial Programming Systems Programming & Scripting Lecture 12: C# Revision 3 Pillars of Object-oriented Programming Encapsulation: each class should be selfcontained to localise changes. Realised through
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
Java Programming Language
Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and
D06 PROGRAMMING with JAVA. Ch3 Implementing Classes
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch3 Implementing Classes PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,
Java Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
Java: overview by example
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: overview by example Bank Account A Bank Account maintain a balance (in CHF) of the total amount of money balance can go
I. INTRODUCTION. International Journal of Computer Science Trends and Technology (IJCST) Volume 3 Issue 2, Mar-Apr 2015
RESEARCH ARTICLE An Exception Monitoring Using Java Jyoti Kumari, Sanjula Singh, Ankur Saxena Amity University Sector 125 Noida Uttar Pradesh India OPEN ACCESS ABSTRACT Many programmers do not check for
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
CS193j, Stanford Handout #4. Java 2
CS193j, Stanford Handout #4 Winter, 2002-03 Nick Parlante Java 2 Student Java Example As a first example of a java class, we'll look at a simple "Student" class. Each Student object stores an integer number
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
Java (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
Computing Concepts with Java Essentials
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann
History OOP languages Year Language 1967 Simula-67 1983 Smalltalk
History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin
SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages
Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition
Java 6 'th edition Concepts INTERNATIONAL STUDENT VERSION CONTENTS PREFACE vii SPECIAL FEATURES xxviii chapter i INTRODUCTION 1 1.1 What Is Programming? 2 J.2 The Anatomy of a Computer 3 1.3 Translating
Software Engineering Techniques
Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary
WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
Habanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance
Introduction to C++ January 19, 2011 Massachusetts Institute of Technology 6.096 Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance We ve already seen how to define composite datatypes
5. Advanced Object-Oriented Programming Language-Oriented Programming
5. Advanced Object-Oriented Programming Language-Oriented Programming Prof. Dr. Bernhard Humm Faculty of Computer Science Hochschule Darmstadt University of Applied Sciences 1 Retrospective Functional
JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.
http://www.tutorialspoint.com/java/java_inheritance.htm JAVA - INHERITANCE Copyright tutorialspoint.com Inheritance can be defined as the process where one class acquires the properties methodsandfields
Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1
Exception Handling Error handling in general Java's exception handling mechanism The catch-or-specify priciple Checked and unchecked exceptions Exceptions impact/usage Overloaded methods Interfaces Inheritance
Capabilities of a Java Test Execution Framework by Erick Griffin
Capabilities of a Java Test Execution Framework by Erick Griffin Here we discuss key properties and capabilities of a Java Test Execution Framework for writing and executing discrete Java tests for testing
Chapter 1 Fundamentals of Java Programming
Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The
Object-Oriented Programming: Polymorphism
1 10 Object-Oriented Programming: Polymorphism 10.3 Demonstrating Polymorphic Behavior 10.4 Abstract Classes and Methods 10.5 Case Study: Payroll System Using Polymorphism 10.6 final Methods and Classes
Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types
Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts
Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions
COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement
CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards
CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards Course Title: TeenCoder: Java Programming Course ISBN: 978 0 9887070 2 3 Course Year: 2015 Note: Citation(s) listed may represent
Introducing Variance into the Java Programming Language DRAFT
Introducing Variance into the Java Programming Language A Quick Tutorial DRAFT Christian Plesner Hansen Peter von der Ahé Erik Ernst Mads Torgersen Gilad Bracha June 3, 2003 1 Introduction Notice: This
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages Corky Cartwright Swarat Chaudhuri November 30, 20111 Overview I In OO languages, data values (except for designated non-oo
INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction
INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science updated 03/08/2012 Unit 1: JKarel 8 weeks http://www.fcps.edu/is/pos/documents/hs/compsci.htm
CISC 181 Project 3 Designing Classes for Bank Accounts
CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on
1 Hour, Closed Notes, Browser open to Java API docs is OK
CSCI 143 Exam 2 Name 1 Hour, Closed Notes, Browser open to Java API docs is OK A. Short Answer For questions 1 5 credit will only be given for a correct answer. Put each answer on the appropriate line.
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
Instance Creation. Chapter
Chapter 5 Instance Creation We've now covered enough material to look more closely at creating instances of a class. The basic instance creation message is new, which returns a new instance of the class.
Assignment # 2: Design Patterns and GUIs
CSUS COLLEGE OF ENGINEERING AND COMPUTER SCIENCE Department of Computer Science CSc 133 Object-Oriented Computer Graphics Programming Spring 2014 John Clevenger Assignment # 2: Design Patterns and GUIs
Part 3: GridWorld Classes and Interfaces
GridWorld Case Study Part 3: GridWorld Classes and Interfaces In our example programs, a grid contains actors that are instances of classes that extend the Actor class. There are two classes that implement
Checking Access to Protected Members in the Java Virtual Machine
Checking Access to Protected Members in the Java Virtual Machine Alessandro Coglio Kestrel Institute 3260 Hillview Avenue, Palo Alto, CA 94304, USA Ph. +1-650-493-6871 Fax +1-650-424-1807 http://www.kestrel.edu/
CS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions
CS 2112 Spring 2014 Assignment 3 Data Structures and Web Filtering Due: March 4, 2014 11:59 PM Implementing spam blacklists and web filters requires matching candidate domain names and URLs very rapidly
7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
11 November 2015. www.isbe.tue.nl. www.isbe.tue.nl
UML Class Diagrams 11 November 2015 UML Class Diagrams The class diagram provides a static structure of all the classes that exist within the system. Classes are arranged in hierarchies sharing common
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER Course Outline (2015) Basic Programming With Procedural & Object Oriented Concepts (C, C++) Training Office# Road: 11, House: 1 A, Nikunja 2, Khilkhet,
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
It has a parameter list Account(String n, double b) in the creation of an instance of this class.
Lecture 10 Private Variables Let us start with some code for a class: String name; double balance; // end Account // end class Account The class we are building here will be a template for an account at
The Interface Concept
Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()
Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class
CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
The first program: Little Crab
CHAPTER 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,
Part I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
Description of Class Mutation Mutation Operators for Java
Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea [email protected] Jeff Offutt Software Engineering George Mason University
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
2 The first program: Little Crab
2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if statement In the previous chapter, we
Creating a Java application using Perfect Developer and the Java Develo...
1 of 10 15/02/2010 17:41 Creating a Java application using Perfect Developer and the Java Development Kit Introduction Perfect Developer has the facility to execute pre- and post-build steps whenever the
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT) Encapsulation and information hiding Aggregation Inheritance and polymorphism OOP: Introduction 1 Pure Object-Oriented
Specialized Programme on Web Application Development using Open Source Tools
Specialized Programme on Web Application Development using Open Source Tools A. NAME OF INSTITUTE Centre For Development of Advanced Computing B. NAME/TITLE OF THE COURSE C. COURSE DATES WITH DURATION
TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction
Standard 2: Technology and Society Interaction Technology and Ethics Analyze legal technology issues and formulate solutions and strategies that foster responsible technology usage. 1. Practice responsible
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
16.1 DataFlavor. 16.1.1 DataFlavor Methods. Variables
In this chapter: DataFlavor Transferable Interface ClipboardOwner Interface Clipboard StringSelection UnsupportedFlavorException Reading and Writing the Clipboard 16 Data Transfer One feature that was
JAVA - EXCEPTIONS. An exception can occur for many different reasons, below given are some scenarios where exception occurs.
http://www.tutorialspoint.com/java/java_exceptions.htm JAVA - EXCEPTIONS Copyright tutorialspoint.com An exception orexceptionalevent is a problem that arises during the execution of a program. When an
Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006
Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006 Final Examination January 24 th, 2006 NAME: Please read all instructions carefully before start answering. The exam will be
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Building Java Programs
Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1-5.2 self-check: #8-17 exercises: #3-6, 10, 12 videos: Ch. 5 #1-2 1 The Random class A Random object generates pseudo-random* numbers.
How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For
Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface
Abstract Classes. Suppose we want write a program that manipulates various types of bank accounts. An Account typically has following features;
Abstract Classes Suppose we want write a program that manipulates various types of bank accounts. An Account typically has following features; Name, AccountNumber, Balance. Following operations can be
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations
OOP Design Handout written by Nick Parlante
CS108, Stanford Handout #12 Young OOP Design Handout written by Nick Parlante OOP Design OOP Design spans a few main themes... - Encapsulation and modularity - API/Client interface design - Inheritance
Lecture 9. Semantic Analysis Scoping and Symbol Table
Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax
Yosemite National Park, California. CSE 114 Computer Science I Inheritance
Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice
Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.
Software Testing Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program. Testing can only reveal the presence of errors and not the
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins [email protected] CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities
AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities The classroom is set up like a traditional classroom on the left side of the room. This is where I will conduct my
Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding
Compiling Object Oriented Languages What is an Object-Oriented Programming Language? Last time Dynamic compilation Today Introduction to compiling object oriented languages What are the issues? Objects
Facebook Twitter YouTube Google Plus Website Email
PHP MySQL COURSE WITH OOP COURSE COVERS: PHP MySQL OBJECT ORIENTED PROGRAMMING WITH PHP SYLLABUS PHP 1. Writing PHP scripts- Writing PHP scripts, learn about PHP code structure, how to write and execute
PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320
CRN:22430/21519 Pace University Spring 2006 CS122/504 Computer Programming II Instructor Lectures Office Hours Dr. Lixin Tao, [email protected], http://csis.pace.edu/~lixin Pleasantville Office: G320, (914)773-3449
Compile-time type versus run-time type. Consider the parameter to this function:
CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();
Syllabus for CS 134 Java Programming
- Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.
Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009
Software Engineering Concepts: Testing Simple Class Example continued Pointers & Dynamic Allocation CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Glenn G. Chappell Department
Android Application Development Course Program
Android Application Development Course Program Part I Introduction to Programming 1. Introduction to programming. Compilers, interpreters, virtual machines. Primitive data types, variables, basic operators,
Curriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
Course Title: Software Development
Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.
