Stéphane Ducasse«ChapterNr».1 Abstract Classes Should not be instantiated (abstract in Java) But can defined complete methods Defines a protocol common.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Identity and Equality Based on material by Michael Ernst, University of Washington.
S.Ducasse Stéphane Ducasse 1 Numbers.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Smalltalk Coding Patterns mostly from Smalltalk Best Practice Patterns Kent Beck Prentice-Hall, 1997.
Principles of Object-Oriented Software Development The language Smalltalk.
Stéphane Ducasse«ChapterNr».1 Arthur Riel Design Heuristics from Object-Oriented Design Heuristics by Arthur Riel Read the Heuristics… –Find reasons why.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse 1 The Taste of Smalltalk.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Stéphane Ducasse 1 Objects to the Roots: Learning from beauty.
03G-1 Everything is an Object Examining builtin classes All these are classes in Little Smalltalk:  Object  Class  Method  Block  Boolean True False.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
12. A bit of Smalltalk. © O. Nierstrasz P2 — A bit of Smalltalk 11.2 Roadmap  Some history  Smalltalk syntax & object model  The Smalltalk environment.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
Stéphane Ducasse«ChapterNr».1 Basic Objects, Conditionals and Loops Booleans Basic Loops Overview of the Collection hierarchy— more than 80 classes: (Bag,
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
1 Chapter 11 Abstract Data Types and Encapsulation Constructs.
Assertions Program correctness. Assertions Java statement – enables you to assert an assumption about your program. – An assertion contains a Boolean.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Intro to Programming Problem 1: Computers have to be told exactly what do to. Problem 2: Computers only understand “Machine language”. Problem 3: Machine.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
The Java Programming Language
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Smalltalk for Unix & W i n d o w s Dennis Smith Cherniak Software Development Corporation.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
Introduction to Java Java Translation Program Structure
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
S.Ducasse Stéphane Ducasse 1 Common Mistakes and Debugging in VW.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
Stéphane Ducasse 1 A Little Journey in the Smalltalk Syntax.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Stéphane Ducasse 1 Abstract Classes.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Sections Inheritance and Abstract Classes
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Interfaces Unit 08.
Java Primer 1: Types, Classes and Operators
Programming Language Concepts (CIS 635)
Object-Oriented Programming
CMSC 202 Java Primer 2.
Chapter 11: Classes, Instances, and Message-Handlers
Sridhar Narayan Java Basics Sridhar Narayan
Copyright 2000, Georgia Tech
Fundaments of Game Design
If-statements & Indefinite Loops
Introduction to Smalltalk
CSE 3302 Programming Languages
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Presentation transcript:

Stéphane Ducasse«ChapterNr».1 Abstract Classes Should not be instantiated (abstract in Java) But can defined complete methods Defines a protocol common to a hierarchy of classes that is independent from the representation choices. A class is considered as abstract as soon as one of the methods to which it should respond to is not implemented (can be a inherited one).

Stéphane Ducasse«ChapterNr».2 Abstract Classes in Smalltalk Depending of the situation, override #new to produce an error. No construct: Abstract methods send the message self subclassResponsibility. Advanced tools check this situation and exploit it.

Stéphane Ducasse«ChapterNr».3 Example Abstract classes are not syntactically different from instantiable classes, BUT a common convention is to use class comments: So look at the class comment and write in the comment which methods are abstract and should be specialized. “Class Boolean is an abstract class that implements behavior common to true and false. Its subclasses are True and False. Subclasses must implement methods for logical operations &, not, controlling and:, or:, ifTrue:, ifFalse:, ifTrue:ifFalse:, ifFalse:ifTrue:”

Stéphane Ducasse«ChapterNr».4 Case Study - Boolean, True, and False

Stéphane Ducasse«ChapterNr».5 Case Study - Boolean, True, and False (II) Abstract method Boolean>>not "Negation. Answer true if the receiver is false, answer false if the receiver is true." self subclassResponsibility Concrete method defined in terms of an abstract method Boolean>>xor: aBoolean "Exclusive OR. Answer true if the receiver is not equivalent to aBoolean." ^(self == aBoolean) not When #not will be defined, #xor: is automatically defined

Stéphane Ducasse«ChapterNr».6 Case Study - Boolean, True, and False (III) False>>not "Negation -- answer true since the receiver is false." ^true True>>not "Negation--answer false since the receiver is true." ^false False>>ifTrue: trueBlock ifFalse: falseBlock "Answer the value of falseBlock. This method is typically not invoked because ifTrue:/ifFalse: expressions are compiled in-line for literal blocks." ^falseBlock value True>>ifTrue: trueBlock ifFalse: falseBlock "Answer the value of trueBlock. This method is typically not invoked because ifTrue:/ifFalse: expressions are compiled in-line for literal blocks." ^trueAlternativeBlock value

Stéphane Ducasse«ChapterNr».7 Implementation Note Note that the Virtual Machine short cuts calls to boolean such as condition for speed reason Virtual machines such as VisualWorks introduced a kind of macro expansion, an optimisation for essential methods and Just In Time (JIT) compilation. A method is executed once and afterwards it is compiled into native code. So the second time it is invoked, the native code will be executed.

Stéphane Ducasse«ChapterNr».8 Case Study - Magnitude 1 > 2 = 2 < 1 = false Magnitude>> < aMagnitude ^self subclassResponsibility Magnitude>> = aMagnitude ^self subclassResponsibility Magnitude>> <= aMagnitude ^(self > aMagnitude) not Magnitude>> > aMagnitude ^aMagnitude < self Magnitude>> >= aMagnitude ^(self < aMagnitude) not Magnitude>> between: min and: max ^self >= min and: [self <= max] 1 2) not = false not = true

Stéphane Ducasse«ChapterNr».9 Case Study - Date Date>>< aDate "Answer whether the argument, aDate, precedes the date of the receiver." year = aDate year ifTrue: [^day < aDate day] ifFalse: [^year < aDate year] Date>>= aDate "Answer whether the argument, aDate, is the same day as the receiver. " self species = aDate species ifTrue: [^day = aDate day & (year = aDate year)] ifFalse: [^false] Date>>hash ^(year hash bitShift: 3) bitXor: day

Stéphane Ducasse«ChapterNr».10 Date Subclass of Magnitude Date today > Date newDay: 15 month: 10 year: > false

Stéphane Ducasse«ChapterNr».11 What you should know What is an abstract class? What can we do with it?