Programming Languages
|
|
- Barry Stevenson
- 6 years ago
- Views:
Transcription
1 TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Mixins Dr. Michael Petter Winter 2014 Mixins 1 / 30
2 What advanced techiques are there besides multiple implementation inheritance? Mixins Introduction 2 / 30
3 Outline Weak implementation inheritance 1 Decorator Problem 2 Wrapper Problem Inheritance in Detail 1 Models for single inheritance 2 Introducing Mixins 3 Modelling Mixins Mixins in the wild 1 Mixins as C++-Pattern 2 Native Mixins Mixins Introduction 3 / 30
4 The Adventure Game Door ShortDoor canpass(person p)? ShortLockedDoor canopen(person p) canpass(person p) LockedDoor canopen(person p) Mixins Introduction The Adventure Game 4 / 30
5 The Adventure Game <interface>doorlike canpass(person p) canopen(person p) Door Short canpass(person p) Locked canopen(person p) ShortLockedDoor canopen(person p) canpass(person p)! Door implements empty methods! Doorlike must anticipate wrappers Mixins Introduction The Adventure Game 5 / 30
6 The Wrapper FileStream read() write() SocketStream read() write()? SynchRW acquirelock() releaselock()! Cannot inherit from both seperately! Creating new wrapping Classes duplicates code Mixins Introduction The Wrapper 6 / 30
7 The Wrapper FileStream read() write() Stream read() write() SocketStream read() write() SynchRW read() write() acquirelock() releaselock()! Undoes specialization! Needs common ancestor Mixins Introduction The Wrapper 7 / 30
8 Let s go back to the basics of inheritance Mixins Mixins Modelling Inheritance 8 / 30
9 Classes and Methods The building blocks for classes are a countable set of method names N a countable set of method bodies B Classes map names to elements from the flat lattice B (called bindings), consisting of: method bodies B or classes C attribute offsets N + (yet) undefined in conflict and the partial order m for each m B Definition (Abstract Class C) A partial function c : N B is called abstract class. Definition (Interface and Class) An abstract class c is called interface iff n pre(c). c(n) =. (concrete) class iff n pre(c). c(n). (with pre beeing the preimage) Mixins Mixins Modelling Inheritance 9 / 30
10 Computing with Classes and Methods Definition (Family of classes C) We call the set of all maps from names to bindings the family of abstract classes C := N B. Several possibilites for composing maps C C: the symmetric join, defined componentwise: b 2 if b 1 = or n / pre(c 1 ) b 1 if b 2 = or n / pre(c 2 ) (c 1 c 2 )(n) = b 1 b 2 = b 2 if b 1 = b 2 otherwise where b i = c i (n) in contrast, the asymmetric join, defined componentwise: { c 1 (n) if n pre(c 1 ) (c 1 c 2 )(n) = c 2 (n) otherwise Mixins Mixins Modelling Inheritance 10 / 30
11 Example: Smalltalk-Inheritance Smalltalk inheritance is the archetype for inheritance in mainstream languages like Java or C# inheriting smalltalk-style establishes a reference to the parent Definition (Smalltalk inheritance ( )) Smalltalk inheritance is the binary operator : C C C, definied by c 1 c 2 = {super c 2 } (c 1 c 2 ) Example: Doors Door = {canp ass, canopen } LockedDoor = {canopen 0x } Door = {super Door} ({canopen 0x } Door) = {super Door, canopen 0x , canp ass } Mixins Mixins Modelling Inheritance 11 / 30
12 Excursion: Beta-Inheritance In Beta-style inheritance the design goal is to provide security from replacement of a method by a different method. methods in parents dominate methods in subclass the keyword inner explicitely delegates control to the subclass Definition (Beta inheritance ( )) Beta inheritance is the binary operator : C C C, definied by c 1 c 2 = {inner c 1 } (c 2 c 1 ) Example (equivalent syntax): class Person { String name ="Axel Simon"; public String tostring(){ return name+inner.tostring();}; }; class Graduate exts Person { public extension String tostring(){ return ", Ph.D."; }; }; Mixins Mixins Modelling Inheritance 12 / 30
13 Extension: Attributes Remark: Modelling attributes is not in our main focus. Anyway, most mainstream languages nowadays are designed so that attributes are not overwritten: Definition (Mainstream inheritance ( )) The exted mainstream inheritance : C C C binds attributes statically: c 2 if n = super (c 1 if n pre(c 1 ) c 2 (n) N + c 2 )(n) = c 1 (n) if n pre(c 1 ) c 2 (n) otherwise Mixins Mixins Modelling Inheritance 13 / 30
14 So what do we really want? Mixins Mixins Introducing Mixins 14 / 30
15 Adventure Game with Code Duplication Door ShortDoor canpass(person p) LockedDoor canopen(person p) ShortLockedDoor canopen(person p) canpass(person p) Mixins Mixins Introducing Mixins 15 / 30
16 Adventure Game with Mixins <mixin>locked canopen(person p) Door canopen(person p) canpass(person p) <mixin>short canpass(person p) mixin compose <mixin>shortlocked Mixins Mixins Introducing Mixins 16 / 30
17 Adventure Game with Mixins class Door { boolean canopen(person p) { return true; }; boolean canpass(person p) { return p.size() < 210; }; } mixin Locked { boolean canopen(person p){ if (!p.hasitem(key)) return false; else return super.canopen(p); } } mixin Short { boolean canpass(person p){ if (p.height()>1) return false; else return super.canpass(p); } } class ShortDoor = Short(Door); class LockedDoor = Locked(Door); mixin ShortLocked = Short o Locked; class ShortLockedDoor = Short(Locked(Door)); class ShortLockedDoor2 = ShortLocked(Door); Mixins Mixins Introducing Mixins 17 / 30
18 Back to the blackboard! Mixins Mixins Modelling Mixins 18 / 30
19 Abstract model for Mixins A Mixin is a unary second order type expression. In principle it is a curried version of the Smalltalk-style inheritance operator. In certain languages, programmers can create such mixin operators: Definition (Mixin) The mixin constructor mixin : C (C C) is a unary class function, creating a unary class operator, defined by: mixin(c) = λx. c x! Note: Mixins can also be composed : Example: Doors Locked = {canopen 0x1234} Short = {canp ass 0x4711} Composed = mixin(short) (mixin(locked)) = λx. Short (Locked x) = λx. {super Locked} ({canopen 0x1234, canp ass 0x4711} x) Mixins Mixins Modelling Mixins 19 / 30
20 Wrapper with Mixins FileStream read() write() SocketStream read() write() <mixin>synchrw acquirelock() releaselock() mixin mixin SynchedFileStream read() write() SynchedSocketStream read() write() Mixins Mixins Modelling Mixins 20 / 30
21 Mixins on Implementation Level class Door { boolean canopen(person p)... boolean canpass(person p)... } mixin Locked { boolean canopen(person p)... } mixin Short { boolean canpass(person p)... } class ShortDoor = Short(Door); class ShortLockedDoor = Short(Locked(Door));... ShortDoor d = new ShortLockedDoor();... Short canpass() Locked super canopen() super Door...! non-static super-references dynamic dispatching without precomputed virtual table Mixins Mixins Modelling Mixins 21 / 30
22 Surely multiple inheritance is powerful enough to simulate mixins? Mixins Mixins Simulating Mixins in C++ 22 / 30
23 Simulating Mixins in C++ template <class Super> class SyncRW : public Super { public: virtual int read(){ acquirelock(); int result = Super::read(); releaselock(); return result; }; virtual void write(int n){ acquirelock(); Super::write(n); releaselock(); }; //... acquirelock & releaselock }; Mixins Mixins Simulating Mixins in C++ 23 / 30
24 Simulating Mixins in C++ template <class Super> class LogOpenClose : public Super { public: virtual void open(){ Super::open(); log("opened"); }; virtual void close(){ Super::close(); log("closed"); }; protected: virtual void log(char*s) {... }; }; class MyDocument : public SyncRW<LogOpenClose<Document>> {}; Mixins Mixins Simulating Mixins in C++ 24 / 30
25 True Mixins vs. C++ Mixins True Mixins super natively supported Mixins as Template do not offer composite mixins C++ Type system not modular Mixins have to stay source code Hassle-free simplified version of multiple inheritance C++ Mixins Mixins reduced to templated superclasses Can be seen as coding pattern Common properties of Mixins Linearization is necessary Exact sequence of Mixins is relevant Mixins Mixins Simulating Mixins in C++ 25 / 30
26 Ok, ok, show me a language with native mixins! Mixins Mixins Native Mixins in Python 26 / 30
27 Ruby class Person attr_accessor :size def = 160 def haskey true class Door def canopen (p) true def canpass(person) person.size < 210 module Short def canpass(p) p.size < 160 and super(p) module Locked def canopen(p) p.haskey() and super(p) class ShortLockedDoor < Door include Short include Locked p = Person.new d = ShortLockedDoor.new puts d.canpass(p) Mixins Mixins Native Mixins in Python 27 / 30
28 Ruby class Door def canopen (p) true def canpass(person) person.size < 210 module Short def canpass(p) p.size < 160 and super(p) module Locked def canopen(p) p.haskey() and super(p) module ShortLocked include Short include Locked class Person attr_accessor :size def = 160 def haskey true p = Person.new d = Door.new d.ext ShortLocked puts d.canpass(p) Mixins Mixins Native Mixins in Python 28 / 30
29 Lessons Learned Lessons Learned 1 Formalisms to model inheritance 2 Mixins provide soft multiple inheritance 3 Multiple inheritance can not compensate the lack of super reference 4 Full extent of mixins only when mixins are 1st class language citizens Mixins Mixins Native Mixins in Python 29 / 30
30 Further reading... Gilad Bracha and William Cook. Mixin-based inheritance. European conference on object-oriented programming on Object-oriented programming systems, languages, and applications (OOPSLA/ECOOP), James Britt. Ruby core reference, December URL Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. Classes and mixins. Principles of Programming Languages (POPL), Mixins Further materials 30 / 30
Programming Languages
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Mixins Dr. Axel Simon and Dr. Michael Petter Winter term 2012 Mixins 1 / 35 What advanced techiques are there besides multiple
More informationProgramming Languages
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Mixins and Traits Dr. Michael Petter Winter 2016/17 What advanced techiques are there besides multiple implementation inheritance?
More informationProgramming Languages
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Traits Dr. Michael Petter Winter 2014 Traits 1 / 27 Is Multiple Inheritance the Ultimate Principle in Reusability? Learning
More informationProgramming Languages
Programming Languages Dr. Michael Petter WS 2016/17 Exercise Sheet 8 Assignment 8.1 Quiz 1. Can Smalltalk Inheritance be used to model Java s inheritance? What about attribute access? 2. In a Trait-based
More informationProgramming Languages
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Dispatching Method Calls Dr. Axel Simon and Dr. Michael Petter Winter term 2012 Dispatching - Outline Dispatching 1 Example
More informationCall by Declaration. Erik Ernst 1. Dept. of Computer Science, University of Aarhus, Denmark
Call by Declaration Erik Ernst 1 Dept. of Computer Science, University of Aarhus, Denmark eernst@daimi.au.dk Abstract. With traditional inheritance mechanisms, a subclass is able to use inherited features
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 30 Topic: Semantic Analysis 2 / 30 Semantic Analysis Chapter 1: Type Checking
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationObject Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia
Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing
More informationTraits: The Formal Model
Traits: The Formal Model Nathanael Schärli, Oscar Nierstrasz, Stéphane Ducasse, Roel Wuyts and Andrew Black Department of Computer Science and Engineering OGI School of Science & Engineering Oregon Health
More informationSuper and Inner Together at Last!
Super and Inner Together at Last! David S. Goldberg University of Utah Robert Bruce Findler University of Chicago Matthew Flatt University of Utah 1 Java-Style Method Overriding m() {... Class A new C().m()
More informationToday. CSE341: Programming Languages. Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins. Ruby instance variables and methods
Today CSE341: Programming Languages Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins Alan Borning Spring 2018 Dynamic dispatch aka late binding aka virtual method calls Call to self.m2() in
More informationInheritance (Chapter 7)
Inheritance (Chapter 7) Prof. Dr. Wolfgang Pree Department of Computer Science University of Salzburg cs.uni-salzburg.at Inheritance the soup of the day?! Inheritance combines three aspects: inheritance
More informationOverview. Elements of Programming Languages. Objects. Self-Reference
Overview Elements of Programming Languages Lecture 10: James Cheney University of Edinburgh October 23, 2017 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces
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 informationProgramming Languages & Paradigms PROP HT Abstraction & Modularity. Inheritance vs. delegation, method vs. message. Modularity, cont d.
Programming Languages & Paradigms PROP HT 2011 Abstraction & Modularity Lecture 6 Inheritance vs. delegation, method vs. message Beatrice Åkerblom beatrice@dsv.su.se 2 Modularity Modularity, cont d. Modular
More informationLecture Notes on Programming Languages
Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered
More informationCSE 341: Programming Languages. Section AC with Nate Yazdani
CSE 341: Programming Languages Section AC with Nate Yazdani aga method dispatch mixins visitor pattern method dispatch what is dispatch method dispatch or just dispatch is the protocol to look up the method
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 informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationJava classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.
CSM 61B Abstract Classes & Interfaces Spring 2017 Week 5: February 13, 2017 1 An Appealing Appetizer 1.1 public interface Consumable { public void consume (); public abstract class Food implements Consumable
More informationUNIVERSITY OF OSLO Department of Informatics. Traits in Java. Master thesis. Kjetil Østerås
UNIVERSITY OF OSLO Department of Informatics Traits in Java Master thesis Kjetil Østerås May 1, 2007 Abstract A trait is a programming language feature which contains a collection of methods that can
More informationRuby: Object-Oriented Concepts
Ruby: Object-Oriented Concepts Computer Science and Engineering College of Engineering The Ohio State University Lecture 8 Classes Classes have methods and variables class LightBulb # name with CamelCase
More informationA Type System for Functional Traversal-Based Aspects
A Type System for Functional Traversal-Based Aspects Bryan Chadwick and Karl Lieberherr March 2 nd 2009 1 / 30 Outline Introduction Example (Pure) Semantics Example (Full Dispatch) Type System Soundness
More informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 59 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites
More informationSoftware Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt
Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Winter Semester 16/17 Decorator Pattern Intent of the Decorator Pattern We need
More informationComp 249 Programming Methodology
Comp 249 Programming Methodology Chapter 7 - Inheritance Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been extracted,
More informationCreating Java Programs with Greenfoot
Creating Java Programs with Greenfoot Using Randomization and Understanding Dot Notation and Constructors 1 Copyright 2012, Oracle and/or its affiliates. All rights Overview This lesson covers the following
More information1. A Remote Proxy helps to hide all the low-level details of exception handling from the proxy Client.
UML diagrams for the design patterns mentioned in the exam are provided at the end of the exam. For some questions the details of the diagram structure will be useful. For other questions, the details
More informationImplementing Layered Designs with Mixin Layers
Implementing Layered Designs with Mixin Layers (joint work with Don Batory) 1 of 19 Objects as components? Modular decomposition is an ideal in software design and implementation - separation of concerns
More informationSmalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)
A Bit of History Some notable examples of early object-oriented languages and systems: Sketchpad (Ivan Sutherland s 1963 PhD dissertation) was the first system to use classes and instances (although Sketchpad
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationCIS 110: Introduction to computer programming
CIS 110: Introduction to computer programming Lecture 25 Inheritance and polymorphism ( 9) 12/3/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Inheritance Polymorphism Interfaces 12/3/2011
More informationPieter van den Hombergh Thijs Dorssers Stefan Sobek. February 10, 2017
Inheritance and Inheritance and Pieter van den Hombergh Thijs Dorssers Stefan Sobek Fontys Hogeschool voor Techniek en Logistiek February 10, 2017 /FHTenL Inheritance and February 10, 2017 1/45 Topics
More informationType Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004
Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationCSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods. Dan Grossman Autumn 2018
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Autumn 2018 What next? Have used classes for OOP's essence: inheritance, overriding, dynamic
More informationMore on Inheritance. Interfaces & Abstract Classes
More on Inheritance Interfaces & Abstract Classes Java interfaces A Java interface is used to specify minimal functionality that a client requires of a server. A Java interface contains: method specifications
More informationChapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language
Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented
More informationSoftware Engineering Design & Construction
Winter Semester 17/18 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt A Critical View on Inheritance 2 A Critical View On Inheritance
More informationOverview. Elements of Programming Languages. Objects. Self-Reference
Overview Elements of Programming Languages Lecture 11: James Cheney University of Edinburgh November 3, 2015 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces
More informationCSE 70 Final Exam Fall 2009
Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15
More information2. The object-oriented paradigm
2. The object-oriented paradigm Plan for this section: Look at things we have to be able to do with a programming language Look at Java and how it is done there Note: I will make a lot of use of the fact
More information8. Polymorphism and Inheritance
8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces
More informationCS558 Programming Languages Winter 2013 Lecture 8
OBJECT-ORIENTED PROGRAMMING CS558 Programming Languages Winter 2013 Lecture 8 Object-oriented programs are structured in terms of objects: collections of variables ( fields ) and functions ( methods ).
More informationJava TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL.
Java TM Introduction Renaud Florquin Isabelle Leclercq FloConsult SPRL http://www.floconsult.be mailto:info@floconsult.be Java Technical Virtues Write once, run anywhere Get started quickly Write less
More informationCSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013
CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Winter 2013 Ruby logistics Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage
More informationTail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)
CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationRuby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework
Ruby logistics CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Autumn 2018 Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage
More informationOOPLs - Inheritance. Inheritance
OOPLs - Inheritance Desirable properties Models of inheritance Class-based: with single, multiple parents Delegation Mix-ins Functionality as code reuse as subtyping 1 Inheritance Data abstraction plus
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Inheritance Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation
More informationDesign issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?
Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables
More informationIntroduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt www.introsoftwaretesting.com OO Software and Designs Emphasis on modularity and reuse puts complexity
More informationIndex. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107
A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105
More informationJam: A Smooth Extension With Java Mixins
Jam: A Smooth Extension With Java Mixins Davide Ancona, Giovanni Lagorio, Ellena Zucca Presentation created by Left-out Jam abstract syntax Formal definitions of Jam static semantics Formal definitions
More informationLesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
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 informationSoftware Engineering Design & Construction
Winter Semester 17/18 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Strategy Pattern The Strategy Pattern in a Nutshell Context
More informationInheritance and Interfaces
Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationPieter van den Hombergh Thijs Dorssers Stefan Sobek. January 11, 2018
Inheritance and Inheritance and Pieter van den Hombergh Thijs Dorssers Stefan Sobek Java Inheritance Example I Visibility peekabo Constructors Fontys Hogeschool voor Techniek en Logistiek January 11, 2018
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 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 informationTraits: Tools and Methodology
Traits: Tools and Methodology Andrew P. Black OGI School of Science & Engineering, OHSU Portland, Oregon, USA Nathanael Schärli Software Composition Group, IAM Universität Bern, Switzerland What are Traits?
More information9/10/2018 Programming Data Structures Inheritance
9/10/2018 Programming Data Structures Inheritance 1 Email me if the office door is closed 2 Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same
More informationLecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction
Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO
More informationImmutability and Design Patterns in Ruby
Immutability and Design Patterns in Ruby Seamus Brady, seamus@corvideon.ie 28/03/2013 Abstract Functional Programming has seen a resurgence in interest in the last few years and is often mentioned in opposition
More informationReusing Classes. Hendrik Speleers
Hendrik Speleers Overview Composition Inheritance Polymorphism Method overloading vs. overriding Visibility of variables and methods Specification of a contract Abstract classes, interfaces Software development
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 informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 10a Andrew Tolmach Portland State University 1994-2017 Object-oriented Programming Programs are structured in terms of objects: collections of variables
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter SoSe 2015 1 / 58 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites Informatik
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More informationTraits in C# Stefan Reichhart Oscar Nierstrasz, Stephane Ducasse. Software Composition Group
Traits in C# Stefan Reichhart stefan_reichhart@student.unibe.ch Software Composition Group Oscar Nierstrasz, Stephane Ducasse Roadmap Project Context / Why Traits? What s a Trait? Flattening Traits? Traits
More informationInheritance Considered Harmful
Inheritance Considered Harmful Inheritance and Reentrance Example: StringOutputStream Robust Variants Forwarding Template Methods / Hooks Inner calls 1 Inheritance Interface Inheritance Subtyping Reuse
More informationArrays Classes & Methods, Inheritance
Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value
More informationCS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.
Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,
More informationOutline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.
Outline Inheritance Class Extension Overriding Methods Inheritance and Constructors Polymorphism Abstract Classes Interfaces 1 OOP Principles Encapsulation Methods and data are combined in classes Not
More informationChapter 7. Inheritance
Chapter 7 Inheritance Introduction to Inheritance Inheritance is one of the main techniques of objectoriented programming (OOP) Using this technique, a very general form of a class is first defined and
More informationProgramming Languages
TEHNISHE UNIVERSITÄT MÜNHEN FKULTÄT FÜR INFORMTIK Programming Languages Multiple Inheritance Dr. Michael Petter Winter term 2015 Multiple Inheritance 1 / 44 Inheritance Principles 1 Interface Inheritance
More information(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days
Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented
More informationC++ Modern and Lucid C++ for Professional Programmers
Informatik C++ Modern and Lucid C++ for Professional Programmers part 13 Prof. Peter Sommerlad Institutsleiter IFS Institute for Software Rapperswil, HS 2015 Inheritance and dynamic Polymorphism base classes,
More informationSoftware Engineering Design & Construction
Winter Semester 16/17 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Decorator Pattern Intent of the Decorator Pattern We need
More informationCISC370: Inheritance
CISC370: Inheritance Sara Sprenkle 1 Questions? Review Assignment 0 due Submissions CPM Accounts Sara Sprenkle - CISC370 2 1 Quiz! Sara Sprenkle - CISC370 3 Inheritance Build new classes based on existing
More informationDecorator Pattern: Introduction
Consider the following situation: Decorator Pattern: Introduction You have a set of subclasses (Subclass1, Subclass2, ) that represent variations of some superclass (Superclass) As usual, the subclasses
More informationInterfaces, Mixins, & Multiple Inheritance
CSE 413 Spring 2011 Interfaces, Mixins, & Multiple Inheritance Based on CSE341, Sp08/Sp11 Overview Essence of object-oriented programming: inheritance, overriding, dynamic-dispatch Classic inheritance
More informationFirst-order function dispatch in a Java-like programming language
First-order function dispatch in a Java-like programming language Steven te Brinke January, 2011 A dissertation submitted to the University of Twente for the degree of Master of Science Department of Computer
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationIdioms for Building Software Frameworks in AspectJ
Idioms for Building Software Frameworks in AspectJ Stefan Hanenberg 1 and Arno Schmidmeier 2 1 Institute for Computer Science University of Essen, 45117 Essen, Germany shanenbe@cs.uni-essen.de 2 AspectSoft,
More informationC09: Interface and Abstract Class and Method
CISC 3120 C09: Interface and Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/28/2017 CUNY Brooklyn College 1 Outline Recap Polymorphism In-class
More informationAnother IS-A Relationship
Another IS-A Relationship Not all classes share a vertical relationship. Instead, some are supposed to perform the specific methods without a vertical relationship. Consider the class Bird inherited from
More informationJava Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.
Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationJava 8 Programming for OO Experienced Developers
www.peaklearningllc.com Java 8 Programming for OO Experienced Developers (5 Days) This course is geared for developers who have prior working knowledge of object-oriented programming languages such as
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 informationThe Java Programming Language
The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation
More information