CS 32. Lecture 1: oops

Similar documents
CS263: Runtime Systems Lecture: High-level language virtual machines

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

INF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.

CS153: Compilers Lecture 11: Compiling Objects

CSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Dynamically-typed Languages. David Miller

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

CS558 Programming Languages

More on object orientation

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

Object Oriented Programming

Object-Oriented Concepts and Design Principles

Concepts of Object-Oriented Programming Peter Müller

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Konzepte von Programmiersprachen

CS 32. Lecture 2: objects good?

New Programming Paradigms

Summary of the course lectures

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 10

Review sheet for Final Exam (List of objectives for this course)

Top Down Design vs. Modularization

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

UC Santa Barbara. CS189A - Capstone. Christopher Kruegel Department of Computer Science UC Santa Barbara

BASIC CONCEPT OF OOP

Object Oriented Programming: Based on slides from Skrien Chapter 2

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle

1. Software Systems Complexity, OO Paradigm, UML

Administrivia. CMSC433, Fall 2001 Programming Language Technology and Paradigms. Administrivia (cont.) Project 1. Copy constructor.

ITI Introduction to Computing II

Programmazione. Prof. Marco Bertini

Announcements. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Intuition: Type Signature is a Specification.

Contracts. Dr. C. Constantinides. June 5, Department of Computer Science and Software Engineering Concordia University Montreal, Canada 1/71

Element: Relations: Topology: no constraints.

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Java Object Oriented Design. CSC207 Fall 2014

Introduction to OO Concepts

Object Model. Object Orientated Analysis and Design. Benjamin Kenwright

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

Principles of Object-Oriented Design

CS558 Programming Languages Winter 2013 Lecture 8

Abstraction. Design fundamentals in OO Systems. Fundamental Software Development Principles

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4

Object-Oriented Design

Implementing objects as in Javascript, Lua, 164 is expensive because object attributes are implemented as hashtable accesses:

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Classes, subclasses, subtyping

Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava

CSC207 Week 3. Larry Zhang

Fibonacci in Lisp. Computer Programming: Skills & Concepts (CP1) Programming Languages. Varieties of Programing Language

Conformance. Object-Oriented Programming Spring 2015

Object oriented programming Concepts

Modern Stored Procedures Using GraalVM

Advanced JML Erik Poll Radboud University Nijmegen

Subtyping (Dynamic Polymorphism)

ITI Introduction to Computing II

Chapter 2: Java OOP I

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

CSE 331 Software Design & Implementation

Design by Contract in Eiffel

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Lecture 4. Types, Memory, Exceptions

CS 3304 Comparative Languages. Lecture 1: Introduction

Exceptions and assertions

CMSC 631 Program Analysis and Understanding. Dynamic Typing, Contracts, and Gradual Typing

SEEM4570 System Design and Implementation Lecture 09 Object Oriented Programming

Overview. Elements of Programming Languages. Objects. Self-Reference

Data Abstraction. Hwansoo Han

Object Oriented Issues in VDM++

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05

Xcode and Swift CS 4720 Mobile Application Development

Assertions. Assertions - Example

CompuScholar, Inc. 9th - 12th grades

Object-Oriented Design

Computer Science 4U Unit 1. Programming Concepts and Skills Modular Design

Fortgeschrittene objektorientierte Programmierung (Advanced Object-Oriented Programming)

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

COURSE 2 DESIGN PATTERNS

Chapter 9. Subprograms

Inheritance and Substitution (Budd chapter 8, 10)

CSE 307: Principles of Programming Languages

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

ECOM 2314 COMPUTER PROGRAMMING II

MIDTERM EXAMINATION - CS130 - Spring 2005

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 10/14/2004 1

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python

CS 32. Lecture 5: Templates

Type Hierarchy. Lecture 6: OOP, autumn 2003

Discussion. Type 08/12/2016. Language and Type. Type Checking Subtypes Type and Polymorphism Inheritance and Polymorphism

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Structured Programming

Protocol Buffers, grpc

Software Implementation

Transcription:

CS 32 Lecture 1: oops

Textbooks Problem Solving in C++ (CS 16) Chapters 10-18 Data Structures with C++ (CS 24) Chapters 12-14 Reader SBPrinter at UCen

Grading Labs 20% Programming Assignments 20% 3 thirdterm exams, each 20%

OOP Stands for Object-Oriented Programming As if you didn t know A way of factoring code A way of encapsulating code

CS 16 Have seen arrays and strings And maybe vectors Right up to structs Next come objects

CS 24 Have already been using classes And maybe templates Did you get as far as tree-traversal? Next come objects

Boundaries One of the basic ways we structure our code is with boundaries Could call them interfaces It worked for living organisms Several times

Access Your object is the combination of state (values) behavior (functions)

Why Centralize? Easier to debug Responsibility (aka blame) is easier to locate Easier to test Individual objects are very amenable to unit testing

Encapsulation Why does the tortoise grow its shell? You want to be similarly defensive with your code You manage access to the internal state

But There s More I got my money the old-fashioned way. I inherited it. Things and their features (state and functions) are not completely disjoint Car has many similar features as Truck Should a Car be a kind of Truck? Should a Truck be a kind of Car?

DRY And there is always the desire to not repeat mechanical patterns but to factor them Abstraction vs Specialization OOP is driven as much by code reuse as it is by encapsulation

Snake in the Garden Hierarchical types need hierarchical type-checking An object s type at runtime may be different (a descendant) from the one declared to the compiler Opens up a whole can o worms

History The idea was in the air in the 60s and 70s Smalltalk at Xerox PARC was the first to go all-in In the 80s came C++ and Object Pascal Java, C# JavaScript? Objective-C, Swift

Top Down Tree-based inheritance structure

Subtypes Inheritance is isomorphic to containment Subtypes are isomorphic to subsets It all seems so simple But

Tension The services an object provides can only expand as it gets more specialized It still has to provide all the services of its parent classes

Contravariance Two opposing forces Subclassing narrows the type but expands the services

Another Snake This led to unexpected problems in language evolution Eiffel Santa Barbara grown! Clear clean Pascal-like language

Eiffel class POINT inherit ANY create make, make_origin feature -- Initialization make (a_x, a_y: INTEGER) make_origin feature -- Access x: INTEGER assign set_x -- Horizontal axis coordinate y: INTEGER assign set_y -- Vertical axis coordinate feature -- Element change set_x (a_x: INTEGER) set_y (a_y: INTEGER) end

Programming Contract API between separate objects is a contract So is the inheritance path in an OO design This led to type-safety issues in Eiffel

Multiple Inheritance Indirectly, maybe inadvertently Is repeated inheritance idempotent? In C++, issues with virtual vs. nonvirtual People got tired of it

Single Inheritance Class can inherit implementation from only one parent Can implement any number of interfaces/protocols/abstract classes

LSP Not a new drug Liskov Substitution Principle Named after Barbara Liskov Subtype must always be OK in context expecting higher type Defining OK takes work

Co-Contravariance Descendant methods must require less, guarantee more Preconditions weaker Postconditions stronger

Next Gen Java Comes with VM also Lacks generics No value types

C# Started out same time as Java Accused of copying Java and C# have diverged

JavaScript What s the big deal with top-down analysis anyway? Just take what exists, and modify it Self JavaScript Prototype-Based Programming

Add-Ons Some languages have added OOP features Perl Python JavaScript PHP MATLAB Lua

Go Dart Scala Swift New Built-In

Read! Reader #2 (Not #1) (most important) (CS 16) Problem Solving Chapter 10 Less important (CS 24) Data Structures Chapter 12 Even less (but don t skip!)