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