MSO Lecture 1. Wouter Swierstra (adapted by HP) September 11, 2017

Similar documents
Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Inheritance and Interfaces

16 Multiple Inheritance and Extending ADTs

PREPARING FOR PRELIM 2

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

ITI Introduction to Computing II

Object Oriented Programming. Java-Lecture 11 Polymorphism

Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department

ITI Introduction to Computing II

Java Object Oriented Design. CSC207 Fall 2014

Design Patterns: State, Bridge, Visitor

CS 142 Style Guide Grading and Details

CSCI 355 Lab #2 Spring 2007

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

INSTRUCTIONS TO CANDIDATES

CS 116 Week 8 Page 1

Polymorphism. Object Orientated Programming in Java. Benjamin Kenwright

CSCI 355 LAB #2 Spring 2004

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Objects First with Java

Credit: The lecture slides are created based on previous lecture slides by Dan Zingaro.

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

CSCI 102 Fall 2010 Exam #1

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Preface A Brief History Pilot Test Results

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

Chapter 3: Inheritance and Polymorphism

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

Chapter 10 Classes Continued. Fundamentals of Java

TIETS14 Introduction to Formal Specification

Chapter 14 Abstract Classes and Interfaces

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

5.6.1 The Special Variable this

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

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

Survey #2. Assignment #3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Static Interface Types.

Logistics. Final Exam on Friday at 3pm in CHEM 102

B. Subject-specific skills B1. Problem solving skills: Supply the student with the ability to solve different problems related to the topics

CSC207 Week 3. Larry Zhang

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Linux Lab Swansea, December 13, 2011.

More on Objects in JAVA TM

CS 111: Programming Fundamentals II

CS Week 15 Page 1

CS111: PROGRAMMING LANGUAGE II

Last class. -More on polymorphism -super -Introduction to interfaces

San José State University Department of Computer Science CS151, Object Oriented Design, Section 04, Fall, 2016 (42968)

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

CE221 Programming in C++ Part 1 Introduction

Object-Oriented Analysis and Design

CS 251, Intermediate Programming Midterm Exam October 9, 2013

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1,2 and 3, Spring 2017

Back to ObjectLand. Contents at: Chapter 5. Questions of Interest. encapsulation. polymorphism. inheritance overriding inheritance super

Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter

CS 134 Programming Exercise 3:

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

CS 101: Computer Programming and Utilization. Abhiram Ranade

CS 11 java track: lecture 3

2. The object-oriented paradigm

Outline EXPERIENCE WITH TWO OOP LANGUAGES IN ONE COURSE. HISTORY Methodology and learning design of the course Experience from classes

MSO Lecture 6. Wouter Swierstra (adapted by HP) September 28, 2017

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

Making Inheritance Work: C++ Issues

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Making Inheritance Work: C++ Issues

You do not have to memorize methods from the Java API. You should know how to use String,

Lecture #2 on Object-Oriented Modeling

CSC324 Principles of Programming Languages

Student Performance Q&A:

Soda Machine Laboratory

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EEC-484/584 Computer Networks

CSE 70 Final Exam Fall 2009

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

CS 251 Intermediate Programming Methods and Classes

Survey #2. Variable Scope. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Scope Static.

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

An Introduction to Subtyping

Compulsory course in Computer Science

17 Multiple Inheritance and ADT Extensions

Slide 1 CS 170 Java Programming 1

CS 520 Theory and Practice of Software Engineering Fall 2018

The Essence of OOP using Java, Nested Top-Level Classes. Preface

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

CS558 Programming Languages

An approach to introductory programming

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Lecture 10: building large projects, beginning C++, C++ and structs

Programming 2. Outline (112) Lecture 0. Important Information. Lecture Protocol. Subject Overview. General Overview.

Object typing and subtypes

MSO Lecture 6. Wouter Swierstra. September 24, 2015

CSE351 Winter 2016, Final Examination March 16, 2016

CS 4349 Lecture October 18th, 2017

Transcription:

1 MSO Lecture 1 Wouter Swierstra (adapted by HP) September 11, 2017

So you think you can program... 2

From nrc.nl 3

Question: why do ICT-projects fail so often? 4

5 Question: why do ICT-projects fail so often? Bad programmers? Bad management? Bad...?

Still you think you can program... 6

7 LEVELS OF ABSTRACTION You already know how to write individual lines of code: for(i=0; i<n; i++) Code is organized into methods: public bool isempty() Methods are organized into classes: public class Student...

8 BEYOND THE F O R LOOP In this course you will learn how to design great software:

9 BEYOND THE F O R LOOP In this course you will learn how to design great software: that is clearly structured;

10 BEYOND THE F O R LOOP In this course you will learn how to design great software: that is clearly structured; that is easy to modify and maintain;

11 BEYOND THE F O R LOOP In this course you will learn how to design great software: that is clearly structured; that is easy to modify and maintain; that makes your customers happy...

12 BEYOND THE F O R LOOP In this course you will learn how to design great software: that is clearly structured; that is easy to modify and maintain; that makes your customers happy...... which is not that obvious

13 Question: which phases may we identify in an ICT-project...?... and where could/will things go wrong?

14

15

16

But once I ve finished coding something, I m done. Right? 17

18

19

There is much more to software construction than just programming. 20

And it is hard to overestimate the volume and importance of maintenance. 21

22 MSO This course assumes you know about for-loops, assignments, methods, and objects; It will teach you to apply this knowledge to organize code into great software that makes your customers happy.

23 TOPICS MSO is a course shared by Information Science and Computer Science students. What should this course cover? Technical? Sociological? Programming? Modelling? Object oriented analysis and design.

REQUIREMENTS ENGINEERING 24

25 OBJECT ORIENTED ANALYSIS Before you start designing software, you need to determine what to build; Analysis is the process of discovering, documenting and maintaining the requirements of a software system Figuring out what the problem is. What does the customer want? How can I translate a customer s wishes to a software design?... By the way, who is the customer?

26 OBJECT ORIENTED ANALYSIS By the way, who is the customer in the case of the bevolkingsregister?

27 OBJECT ORIENTED ANALYSIS By the way, who is the customer in the case of the bevolkingsregister? The clerk?

28 OBJECT ORIENTED ANALYSIS By the way, who is the customer in the case of the bevolkingsregister? The clerk? The citizen?

29 OBJECT ORIENTED ANALYSIS By the way, who is the customer in the case of the bevolkingsregister? The clerk? The citizen? The municipal authorities?

30 OBJECT ORIENTED ANALYSIS By the way, who is the customer in the case of the bevolkingsregister? The clerk? The citizen? The municipal authorities? The national government?

31 OBJECT ORIENTED ANALYSIS By the way, who is the customer in the case of the bevolkingsregister? The clerk? The citizen? The municipal authorities? The national government?...?

32 OBJECT ORIENTED DESIGN How should I organize code into classes? Which classes are related? How are classes related? What are the properties of a good design?

33 ANALYSIS AND DESIGN This course teaches both analysis and design. Analysis is a soft skill talking to customers and figuring out what they want. Design is more technical figuring out the right high-level structure of your code.

34 Anonymous CS student: Why is this course interesting for me, all I want to do is program?

35 MSO FOR CS STUDENTS Weeks of programming can save you hours of planning Anon Learning about good software design will make you a better programmer. This course will train you to think about code at a high-level of abstraction; A good design results in better code.

36 Anonymous IS student: Why is this course interesting for me? As a project manager, I ll never have to program myself.

Close your eyes and picture your most beautiful memory. 37

Now imagine having to commission an artist to paint that memory... 38

To catch the atmosphere of that beautiful memory, you want an impressionist style painting... 39

40

So you will have to communicate with that artist... in French. 41

42 THE METAPHOR There is a huge difference between having a great idea for a software product...... and implementing it. The only way you will ever succeed in getting the implementation you want, is if you learn to communicate clearly with software developers. Communication requires speaking the same language and requires knowing the same concepts. This course offers a tremendous opportunity for cooperation between computer scientists and information scientists!

43 MSO FOR IS This course will teach you how to translate a customer s wishes to a concrete design that developers can implement. You will learn the language to communicate high-level ideas to developers. It will teach you what constitutes good design and help you identify good developers.

44 Anonymous GameTech student: Why is this course interesting for me? I just want to design computer games?

Suppose you just wrote Super Mario Brothers... 45

46... AND THEN THE FEEDBACK COMES IN. The characters are cute

47... AND THEN THE FEEDBACK COMES IN. The characters are cute I like the mushrooms and turtle shells.

48... AND THEN THE FEEDBACK COMES IN. The characters are cute I like the mushrooms and turtle shells. But the gameplay is no good.

49... AND THEN THE FEEDBACK COMES IN. The characters are cute I like the mushrooms and turtle shells. But the gameplay is no good.... and then your boss says

50... AND THEN THE FEEDBACK COMES IN. The characters are cute I like the mushrooms and turtle shells. But the gameplay is no good.... and then your boss says Maybe we should put the same characters in go karts...

51... AND THEN THE FEEDBACK COMES IN. The characters are cute I like the mushrooms and turtle shells. But the gameplay is no good.... and then your boss says Maybe we should put the same characters in go karts...... and add bananas.

52 MSO FOR GAMETECH The hardest part about building a game is getting the gameplay just right; This involves a lot of test-rewrite development iterations; Designing your game to be easy to adapt to these changes makes your life much easier!

53 COURSE ORGANIZATION Lectures theory Lab sessions practice Four small assignments deadlines online now; One large design project.

54 REGULAR ASSIGNMENTS: THE CARROT AND THE STICK I will set four exercises that you must submit. Each exercise will be marked on the scale: A; B; D; F. If you score AABB or better, you will receive an extra 0.5 on your final exam. If you score BBDD or worse, you will lose 0.5 on your final exam. If you fail an exercise (F), you will fail the course. If you fail one exercise, you will be given the opportunity to complete a remedial exercise ( herkansing ), provided your final mark for the whole course is at least a 6.

55 FINAL MARK One midterm exam (20%); Final exam (50%); Design project (30%)

56 MATERIAL Shalloway and Trott, Design Patterns Explained, 2nd edition, Addison Wesley; Code uses Java (but there is almost no code in the book); C# code available from the book s website. Larman, Applying UML and patterns, Prentice Hall. (slides and schedule refer to the second edition) Online resources will be added to the website. Slides and notes.

Who, what, when, where? 57

58 WHO Lecturers: Anna-Lena Lamprecht, Hans Philippi Lab leads: Nico Naus, Hans Philippi Lab assistants: David van der Sar, Lex de Kogel, Jelle Kroon, Iwan Boksebeld, Jasper Berends, Wessel Radstok

59 TOWARDS OBJECT-ORIENTED DESIGN Before talking about more about object oriented analysis and design, let s review some concepts: inheritance; subclass/superclass; polymorphism; abstract classes.

60 EXAMPLE: CIRCLE class Circle { protected float radius; public Circle (float r){ radius = r; } } public float Area () { return Math.PI * radius * radius; }...

61 CLASSES VS INSTANCES We distinguish between the type of integers int and a concrete integer 1337. Similarly, we should be careful to distinguish between the description of a class, such as the Circle class,...... and instances of this class, such as c = new Circle(3); Such instances are called objects.

62 EXTENDING CIRCLES What should I do if I want to have a new kind of circle, ColorCircle, that behaves just like a circle, but also has color information?

63 EXTENDING CIRCLES What should I do if I want to have a new kind of circle, ColorCircle, that behaves just like a circle, but also has color information? Copy the original Circle into a new ColorCircle class.

64 EXAMPLE: COLORCIRCLE class ColorCircle { protected float radius; protected Color color; public ColorCircle (float r, Color c) { radius = r; color = c; } } public float Area () { return Math.PI * radius * radius; }...

65 EXTENDING CIRCLES What should I do if I want to have a new kind of circle, ColorCircle, that behaves just like a circle, but also has color information? Copy the original Circle into a new ColorCircle class. But now suppose I want to change the type of Area() to double. Then I will need to change the code on two different places. And suppose I want to add a method Circumference(). Then I will have to add this code on two different places. This smells of bad design...

66 AN ALTERNATIVE SOLUTION INHERITANCE class ColorCircle : Circle { protected Color color;... }

67 AN ALTERNATIVE SOLUTION INHERITANCE class ColorCircle : Circle { protected Color color;... } This way, we declare that the class ColorCircle inherits the methods and variables of Circle class...

68 AN ALTERNATIVE SOLUTION INHERITANCE class ColorCircle : Circle { protected Color color;... } This way, we declare that the class ColorCircle inherits the methods and variables of Circle class...... only it also has color information.

69 AN ALTERNATIVE SOLUTION INHERITANCE class ColorCircle : Circle { protected Color color;... } This way, we declare that the class ColorCircle inherits the methods and variables of Circle class...... only it also has color information. A change to the original Circle class methods automatically propagates to the ColorCircle class.

70 TERMINOLOGY We say that ColorCircle is a subclass of Circle; Or that Circle is the superclass of ColorCircle.

71 POLYMORPHISM We have defined a method float Area() within the class Circle We can call this method on all kinds of circles: Circle mycircle1 = new Circle(4); Circle mycircle2 = new ColorCircle(6, Color.Red);... float area1 = mycircle1.area(); float area2 = mycircle2.area();

72 POLYMORPHISM We have defined a method float Area() within the class Circle We can call this method on all kinds of circles: Circle mycircle1 = new Circle(4); Circle mycircle2 = new ColorCircle(6, Color.Red);... float area1 = mycircle1.area(); float area2 = mycircle2.area(); We call this phenomenon polymorphism.

73 A PROBLEM Suppose you want to define objects to represent circles, squares, rectangles, and curves. A Square class could be a subclass of a Rectangle class. But what is a good choice of superclass for both the Rectangle and Circle classes?

74 ABSTRACT CLASS An abstract class is a class without instances. For example: abstract class Shape { } public abstract void draw() {... } This declares a dummy superclass, with a single method draw Individual subclasses, such as Circle, Square, Rectangle or Curve, should override the draw method with their own implementation.

75 ANOTHER PROBLEM Now suppose you want to draw various buttons and controls on a canvas. Finding a nice layout requires that you know the size of all these objects.... but they are not closely related enough to fall under a single superclass.

76 INTERFACES An interface is a signature describing a series of methods or properties; A class implements an interface if it defines these methods. interface IDimensions { float getlength(); float getwidth(); }

77 INTERFACES OR ABSTRACT CLASSES? Interfaces: A class may implement many interfaces. An interface only defines public methods properties. Used to organize objects the share some common property. Abstract classes: A class has one single superclass. An abstract class may also specify private methods and properties. Used to group closely related objects.

78 INTERFACES: TECHNICAL TERM The term interface can mean different things: Interface in the IDimension sense But we also talk about the interface of a system or class as what gets exposed to the outside world. When we talk about interfaces, we ll usually refer to the second notion.

79 HOW MUCH CODE? This course will not require a lot of coding...

80 HOW MUCH CODE? This course will not require a lot of coding...... but we will study programs.

81 HOW MUCH CODE? This course will not require a lot of coding...... but we will study programs. We will look at what code does and how it is structured, without worrying too much about how it is implemented exactly.

82 HOW MUCH CODE? This course will not require a lot of coding...... but we will study programs. We will look at what code does and how it is structured, without worrying too much about how it is implemented exactly. Is this program well designed? as opposed to The loop on line 325 of the Foo class is wrong.

83 OUTLINE OF THE COURSE First four sessions: focus on the analysis and design process, including UML

84 OUTLINE OF THE COURSE First four sessions: focus on the analysis and design process, including UML Later sessions: it is a good thing to learn from your failures...

85 OUTLINE OF THE COURSE First four sessions: focus on the analysis and design process, including UML Later sessions: it is a good thing to learn from your failures... but it is better to learn from other peoples failures: focus on design patterns

86 REFERENCES The following references can be helpful to refresh or extend your knowledge of C#: https://www.tutorialspoint.com/csharp/ topics: inheritance, polymorphism, interfaces http://csharp.net-tutorials.com/ topics: inheritance, abstract classes

87 LABS Lab assistance starts on Thursday September 14