Programming 2. Object Oriented Programming. Daniel POP

Size: px
Start display at page:

Download "Programming 2. Object Oriented Programming. Daniel POP"

Transcription

1 Programming 2 Object Oriented Programming Daniel POP

2 Week 14

3 Wrap-up last week Software Development Process Activities Approaches (models) Object-Oriented Analysis Overview Discovering objects Object relationships Use cases Designing the user interface Case study: University Registration System

4 Agenda Object-Oriented Design Overview and concepts Structuring objects, attributes and services OOD principles Case study: University Registration System

5 Object-oriented design DEFINITION [Object-oriented design] OOD is the discipline of defining the objects and their interactions to solve a business problem that was identified and documented during object oriented analysis. Covers software architecture activities of software development process. Inputs of OOD step: Deliverables of OOA step (conceptual model, use cases, UI documentation, other documents) Deliverables (output) of OOD step Class diagram static structure diagram that describes the structure of a system by showing the system's classes, their attributes, and the relationships between the classes; Sequence diagram shows different processes or objects that live simultaneously, and the messages exchanged between them, in the order in which they occur.

6 OOD concepts WHAT DO WE DO IN OOD STEP? Define objects: identify attributes, behavior and services exposed by objects. Create class diagram from conceptual diagram. Define application framework (if applicable): Application framework is a term usually used to refer to a set of libraries or classes that are used to implement the standard structure of an application for a specific operating system. By bundling a large amount of reusable code into a framework, much time is saved for the developer, since he/she is saved the task of rewriting large amounts of standard code for each new application that is developed. Identify persisted objects/data (if applicable): Identify objects that have to be persisted. If relational database is used design the object relation mapping (data layout and database services). Identify, define remote objects (if applicable). Evaluate existing OO programming language and choose the most appropriate one Evaluate the OO design Define the testing strategy: unit testing, non-regression testing, integration testing etc. HOW DO WE DO IT? Base on experience, common-sense, using OOD principles and design patterns.

7 Structuring objects Generalization-specialization hierarchies (is-a) use inheritance to factor-out common attributes and behavior of discovered objects does the union of all specializations cover the set described by generalization? are the specializations mutually exclusive? Example: Shape, Ellipse, Point Multiple inheritance tend to complicate the hierarchy; conflicts may appear between similar attributes/behavior inherited from the two distinct base classes; should be used with caution ; Java-like approach: extend a single representation and implement many behaviors Multiple inheritance is like a parachute; you don t always need it, but when you do, you re really happy to have it at hand. (G. Booch) Whole-part hierarchies (has-a) Example: Person has 1 Body, 0 or 2 Arms, 1 Head etc.; A Polyline has 2..N Points. the whole does not inherit behavior from parts => inheritance is not applicable here. usually, whole-part relationships are identified after gen-spec Note: Attributes and behavior are added in later steps.

8 Object attributes Discovering attributes use a first-person perspective ( personification ) analyze the problem, interview the customer Placing attributes in a class hierarchy which class in a hierarchy is the most appropriate place-holder for an attribute? Define attribute domain, i.e. what are the legal values the attribute can take. The relationships between objects are implemented as attributes as well, but these attributes aren t explicitly presented as normal object s attributes, though they are part of the object s state. During this phase, the class hierarchy is revised Examples: a Point has 2 coordinates, denoted X, Y that can only take positive values.

9 Object behaviour DEFINITION [Behavior, Service] A behavior describes an activity of an object. A service defines the relationship to other model components. Represented using UML s behavior and interaction diagrams (e.g. Activity, State Machine etc.) Identify possible object s states and then explore meaningful connections (state changes). Have all states been defined? Are all the states reachable? In each state, does the object respond properly to all possible conditions? Involve interactions with other objects that will be detailed in object services. Example: Add Department Add Department - this diagram shows how new departments are added to the system. The process starts by the user pressing the Add Department button on the University window. This brings up a small dialog where the name of the new department can be entered. When the user presses OK, a create message is sent to create the new Department. This message contains a single attribute: the name of the new Department.

10 Object services (I) Discovering required services (= member functions) based on their types: implicit services: create a new instance (constructor), destructor, get/set value of attributes (getter/setter) etc. (usually not shown in diagrams) services associated with message connections: identify the messages sent to that objects in previous steps and add services to handle them; can be suggested by behavior diagram(s) services associated with object relationships: establish/disconnect the relationships between objects (relationships have been identified in OOA phase) (e.g. Polyshape has Points => add/remove/change points to polyshape object) services associated with attributes: protect some attributes, modify an attribute only together with other attribute, synchronization in real-time systems etc.

11 Object services (II) Messages are exchanged between objects in order to execute a full service. Graphical representation: as member functions in class diagram as message connectors in various interaction diagrams (Collaboration/Sequence, Communication, Interaction etc.) Implemented as public member functions Example: dynamic representation see AddSection in the Case Study section static representation Person + Age() : double

12 OOD Key Principles Motto: Imitation is the sincerest form of not being stupid. DEFINITION [Design principle] A design principle is a basic tool or technique that can be applied to designing or writing code to make that code more maintainable, flexible, or extensible. Key OOD principles are: OCP DRY SRP LSP

13 Open-Close Principle The Open-Closed Principle (OCP): Classes should be open for extension and closed for modification. Allowing change, but without modifying existing code. It offers flexibility. Use inheritance to extend/change existing working code and don t touch working code. OCP can also be achieved using composition. class Shape { int type; void drawpolygon() { /*... */ void drawpoint() { /*... */ public: void draw(); ; void Shape::draw() { switch(type) { case POLYGON: drawpolygon(); break; case POINT: drawpoint(); break; NOK OK class Shape { public: virtual void draw() = 0; ; class Polygon : public Shape { public: void draw(); ; class Point : public Shape { public: void draw(); ; void Polygon::draw() { /*...*/ Void Point::draw() { /*... */

14 Don t Repeat Yourself The Don t Repeat Yourself Principle (DRY). Avoid duplicate code by abstracting out things that are common and placing those things in a single location. No duplicate code => ONE requirement in ONE place! This principle can and should be applied everywhere (e.g. in Analysis phase don t duplicate requirements or features!) Code is easier and safer to maintain because we have to change only one place. String::String(const char* pch) { if(pch!=null) { str = new char[(sz=strlen(pch))+1]; strcpy(str, pch); else { str = NULL; sz = 0; void String::set(const char* pch) { if(str!=null) delete [] str; if(pch!=null) { str = new char[(sz=strlen(pch))+1]; strcpy(str, pch); else { str = NULL; sz = 0; NOK OK /* private */ String::init(const char* pch) { if(pch!=null) { str = new char[(sz=strlen(pch))+1]; strcpy(str, pch); else { str = NULL; sz = 0; String::String(const char* pch) { init(pch); void String::set(const char* pch) { if(str!=null) delete [] str; init(pch);

15 Single Responsibility Principle The Single Responsibility Principle (SRP). Every object in your system should have a single responsibility, and all the object s services should be focused in carrying out that single responsibility. ONLY one reason to change something! Code will be simpler and easier to maintain. Example: Container and Iterator (Container manages objects; Iterator traverses the container) How to spot multiple responsibilities? Forming sentences ending in itself. Automobile Start() Stop() ChangeTires() Drive() GetOilLevel() The Automobile The Automobile The Automobile The Automobile The Automobile start itself. stop itself. changetires itself. Drive itself. getoillevel itself. NOK Automobile Start() Stop() GetOilLevel() Driver Drive(Automobile) Mechanic OK ChangeTires(Automobile)

16 Liskov Substitution Principle The Liskov Substitution Principle (LSP). Subtypes must be substitutable for their base types. Well-designed class hierarchies Subtypes must be substitutable for their base class without things going wrong. Board tiles: Tile[][] gettile(int, int) settile(tile, int, int) Board tiles: Tile[][] gettile(int, int) settile(tile, int, int) 3DBoard tiles3d: Tile[][][] gettile(int, int, int) settile(tile, int, int, int) void f() { Board* board = new 3DBoard; // ok! // doesn t make sense for a 3D board board->gettile(1,7); All member functions of Board are members of 3DBoard as well (that s inheritance), but, being defined for 2D world, they don t make sense in the new context (3D world). NOK OK 3DBoard boards: Board[] gettile(int, int, int) settile(tile, int, int, int) Tile 3DBoard::getTile(int x, int y, int z) { return boards[x].gettile(y, z);

17 Delegation pattern DEFINITION [Delegation] Delegation is handing of a task over another object. Alternative to inheritance. Advantage over inheritance: behavior can be changed at run-time class A { public: virtual void foo() { printf( An A at work."); ; class B { A* pa; public: B(A* aa) : pa(aa) { void seta(a* aa) { pa = aa; class AA : public A { public: virtual void foo() { printf("an AA at work."); ; ; virtual void foo() { // delegate the task to object pa pa->foo(); void main() { B b(new A); b.foo(); // A behavior b.seta(new AA); b.foo(); // AA behavior Delegation is best used when you want to use another class s behavior as is, without changing that behavior. Example: Board, 3DBoard example

18 Class inheritance vs. object composition Class inheritance (white-box) Visibility Static (compile time) Easy to understand (and use) Breaks encapsulation principle Reusing problems Large class hierarchies; fewer objects Object composition (black-box) Reuse Dynamic (can change at run-time through instantiation) Difficult to understand Doesn t break encapsulation principle Keeps each class encapsulated and focused on one task Small class hierarchies; more objects

19 Case study: Class Diagrams This diagram shows that Teacher and Student are both subclasses of Person. Each Person object contains a name and an address. Each Teacher object contains a name and an address (both inherited from Person), plus a title. Each Student object contains a name and an address (again, inherited from Person) and a total number of credits earned so far.

20 Case study: Class Diagrams These diagrams show the view classes associated with the University, Department, Course and Section classes. The UniversityView class contains a method which creates a university window. This window displays the University s name, address, and phone number. It also displays a list of the departments in the university. The UniversityView class also contains code for creating a small dialog where the name of a new department can be entered. This dialog is brought up by pressing the Add Department button on the university window. The DepartView class contains a method which creates a department window. This window displays the department s name. It displays a list of the teachers employed by the department. It displays a list of the students supervised by the department. The last item displayed by the window is a list of the courses offered by the department. There are buttons on the window for adding new teachers, new students, and new courses. The DepartView class also contains code which creates a small dialog where a new course s number and title can be entered. This dialog is brought up by pressing the Add New Course button on the department window. The AddSectionView class contains a method for creating the AddSection window. This window has fields for entering a new section s course number, teacher s name, days of the week, and start and end times. The OK button at the bottom is pressed to actually add the section to the system. The new section will be assigned the next available section number, ie. if the course already has sections 1 and 2, then this section will get a section number of 3. The AddStudentToSectionView class contains methods for interacting with a student via a touch-tone telephone. The student can enter the course number and section number and their name. The CourseView class contains a method which creates a Course window. This window displays the course s title, number, description, and credits. This window also displays a list of the sections offered. The SectionView class contains a method which creates a Section window. This window displays the section s number, days of the week, and start and end times. The window also displays the teacher teaching this section and a list of the students signed up for this section.

21 Case study: Collaboration Diagrams Add Department - this diagram shows how new departments are added to the system. The process starts by the user pressing the Add Department button on the University window. This brings up a small dialog where the name of the new department can be entered. When the user presses OK, a create message is sent to create the new Department. This message contains a single attribute: the name of the new Department. Add Section - this diagram shows how a new section is added to the system. The process starts in the AddSectionView where a course number, teacher s name, days of the week, and start and end times are entered. When the user presses the OK button, an addsection message is sent to the Department object. This message contains all the information entered. The Department object receives this message and converts the course number to a pointer to the Course object so that it can then send a message to this Course Object. The teacher s name is converted to a pointer to the Teacher object. Then an addsection message is sent from the Department object to the Course object. This message contains a pointer to the teacher who is teaching the course, the days of the week, and the start and end times. The Course object receives this message and then sends a create message to get this new Section object created. This create message contains six arguments: a pointer back to the Course object (needed because all Section objects have links back to the associated Course object), a pointer to the teacher teaching this Course, the number of this Section (computed by the Course object since it will know how many Sections have already been created), the days of the week, and the start and end times. The Course object will get back a pointer to this new Section which it should add to its list of Sections. During the creation of the new Section, an addsection message must be sent to the Teacher who is teaching the course so that this Teacher object can update its list of Sections which it is teaching.

22 Further Reading [McLaughlin, 2006] Brett McLaughlin, Gary Pollice, David West Head First Object-Oriented Analysis and Design, O'Reilly, 2006 [Pages ] [Sussenbach, 1999] Rick Sussenbach Object-oriented Analysis & Design (5 Days), DDC Publishing Inc, 1999, ISBN , [Chapter 13, 14] [Yourdon, 1994] Edward Yourdon Object-oriented Systems Design, Prentice-Hall International Inc, 1994 [Chapter 12, 13, 14] [Stroustrup, 1997] Bjarne Stroustrup The C++ Programming Language 3rd Edition, Addison Wesley, 1997 [Section ] A OOD case study for a user interface hierarchy

23 This is NOT the end. If you like object oriented analysis and design, you will find design patterns very interesting. Here is a starting point: or you may want to take a look inside Bruce Eckel s Thinking in C++ book: or to its Java counterpart: va/thinkinginjava.pdf or join the Timisoara s Java user group community at

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

Software Development

Software Development Software Development and Professional Practice Object-Oriented Design Part the Third: (in which we revisit several parts of the OOA&D process, culminating in some general design principles) Object Oriented

More information

Originality is Overrated: OO Design Principles

Originality is Overrated: OO Design Principles Originality is Overrated: OO Design Principles Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 13 10/09/2007 University of Colorado, 2007 1 Lecture Goals Review material from

More information

Programmazione. Prof. Marco Bertini

Programmazione. Prof. Marco Bertini Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Software engineering techniques and tools A fool with a tool is still a fool. - Grady Booch Use case A use case

More information

Software Engineering

Software Engineering Software Engineering CSC 331/631 - Spring 2018 Object-Oriented Design Principles Paul Pauca April 10 Design Principles DP1. Identify aspects of the application that vary and separate them from what stays

More information

08. DESIGN PRINCIPLES. Originality is Overrated PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT

08. DESIGN PRINCIPLES. Originality is Overrated PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 08. DESIGN PRINCIPLES Originality is Overrated it s not about doing it your way this week is all about doing it the smarter, faster way. Design principle

More information

Summary of the course lectures

Summary of the course lectures Summary of the course lectures 1 Components and Interfaces Components: Compile-time: Packages, Classes, Methods, Run-time: Objects, Invocations, Interfaces: What the client needs to know: Syntactic and

More information

Programming 2. Object Oriented Programming. Daniel POP

Programming 2. Object Oriented Programming. Daniel POP Programming 2 Object Oriented Programming Daniel POP Week 5 Agenda 1. Modifiers: friend 2. Objects Wrap-up last week Self-reference Modifiers: static const mutable Object Oriented Programming Friends (I)

More information

Course Administration

Course Administration CS 246: Software Abstraction and Specification (Software Engineering Section) Lecture 1 Course Administration http://www.student.cs.uwaterloo.ca/~cs247 Calendar Description CS 247 Software Engineering

More information

Object Relationships

Object Relationships Object Relationships Objects can work together in three different types of relationships: Uses: An object can use another to do some work (association). Composition: A complex object may be composed of

More information

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

Week 7. Statically-typed OO languages: C++ Closer look at subtyping C++ & Subtyping Week 7 Statically-typed OO languages: C++ Closer look at subtyping Why talk about C++? C++ is an OO extension of C Efficiency and flexibility from C OO program organization from Simula

More information

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Chapter 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 information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

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

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development INTRODUCING API DESIGN PRINCIPLES IN CS2 Jaime Niño Computer Science, University of New Orleans New Orleans, LA 70148 504-280-7362 jaime@cs.uno.edu ABSTRACT CS2 provides a great opportunity to teach an

More information

CHAPTER 6: CREATIONAL DESIGN PATTERNS

CHAPTER 6: CREATIONAL DESIGN PATTERNS CHAPTER 6: CREATIONAL DESIGN PATTERNS SESSION III: BUILDER, PROTOTYPE, SINGLETON Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E. Otero For non-profit

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Ray John Pamillo 1/27/2016 1 Nokia Solutions and Networks 2014 Outline: Brief History of OOP Why use OOP? OOP vs Procedural Programming What is OOP? Objects and Classes 4 Pillars

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Programming 2. Object Oriented Programming. Daniel POP

Programming 2. Object Oriented Programming. Daniel POP Programming 2 Object Oriented Programming Daniel POP Week 2 Agenda 1. Basic OOP concepts 1. Class 2. Object 3. Message 2. Scopes 3. Classes 1. Declaration 2. Implementation 3. Accessing class members 4.

More information

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli Identify and overcome the difficulties encountered by students when learning how to program List and explain the software development roles played by students List and explain the phases of the tight spiral

More information

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003 Outline Object Oriented Programming Autumn 2003 2 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge

More information

CSE 70 Final Exam Fall 2009

CSE 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 information

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

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized

More information

Good-Enough Design. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 11 02/17/2009

Good-Enough Design. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 11 02/17/2009 Good-Enough Design Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 11 02/17/2009 University of Colorado, 2009 1 Goals 2 Review material from Chapter 5 of Pilone & Miles Software Design

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.

More information

The following topics will be covered in this course (not necessarily in this order).

The following topics will be covered in this course (not necessarily in this order). The following topics will be covered in this course (not necessarily in this order). Introduction The course focuses on systematic design of larger object-oriented programs. We will introduce the appropriate

More information

Programming 2. Object Oriented Programming. Daniel POP

Programming 2. Object Oriented Programming. Daniel POP Programming 2 Object Oriented Programming Daniel POP Week 4 Agenda 1. Self-reference 2. Modifiers: static 3. Modifiers: const 4. Modifiers: mutable 5. Modifiers: friend Wrap-up last week Constructors Definition:

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

The major elements of the object-oriented model

The major elements of the object-oriented model The major elements of the object-oriented model Abstraction Encapsulation Inheritance Modularity Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Reusing Classes Hierarchy 2 An abstraction

More information

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 Object Fundamentals Part Three Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Department of Computer Engineering Lecture 12: Object-Oriented Principles Sharif University of Technology 1 Open Closed Principle (OCP) Classes should be open for extension but closed

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

C++ Modern and Lucid C++ for Professional Programmers

C++ 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 information

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN CHAPTER 5: PRINCIPLES OF DETAILED DESIGN SESSION II: STRUCTURAL AND BEHAVIORAL DESIGN OF COMPONENTS Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E.

More information

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

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

SYLLABUS / FIȘA DISCIPLINEI

SYLLABUS / FIȘA DISCIPLINEI SYLLABUS / FIȘA DISCIPLINEI 1. Information on the study programme 1.1. Institution West University of Timișoara 1.2. Faculty Mathematics and Computer Science 1.3. Department Computer Science 1.4. Study

More information

Introduction to Design Patterns

Introduction to Design Patterns Introduction to Design Patterns First, what s a design pattern? a general reusable solution to a commonly occurring problem within a given context in software design It s not a finished design that can

More information

Influence of Design Patterns Application on Quality of IT Solutions

Influence of Design Patterns Application on Quality of IT Solutions Influence of Design Patterns Application on Quality of IT Solutions NADINA ZAIMOVIC, DZENANA DONKO Department for Computer Science and Informatics Faculty of Electrical Engineering, University of Sarajevo

More information

Object-Oriented Programming. Objects. Objects. Objects

Object-Oriented Programming. Objects. Objects. Objects References: Beginning Java by Jacquie Barker; Designing Object-Oriented Software by Rebecca Wirfs- Brock;Object-oriented Analysis & Design by Grady Booch; Sara Stoecklin Object Oriented Programming defined

More information

CSE351 Winter 2016, Final Examination March 16, 2016

CSE351 Winter 2016, Final Examination March 16, 2016 CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,

More information

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 9 OO modeling Design Patterns Structural Patterns Behavioural Patterns

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. 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 information

Inheritance and Substitution (Budd chapter 8, 10)

Inheritance and Substitution (Budd chapter 8, 10) Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various

More information

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

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Outline Subtype polymorphism Subtyping vs. subclassing Liskov Substitution Principle (LSP) Function subtyping Java subtyping Composition:

More information

Data Abstraction. Hwansoo Han

Data 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 information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

Object- Oriented Design with UML and Java Part I: Fundamentals

Object- Oriented Design with UML and Java Part I: Fundamentals Object- Oriented Design with UML and Java Part I: Fundamentals University of Colorado 1999-2002 CSCI-4448 - Object-Oriented Programming and Design These notes as free PDF files: http://www.softwarefederation.com/cs4448.html

More information

Vector and Free Store (Pointers and Memory Allocation)

Vector and Free Store (Pointers and Memory Allocation) DM560 Introduction to Programming in C++ Vector and Free Store (Pointers and Memory Allocation) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java

Object-Oriented Software Engineering Practical Software Development using UML and Java Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes Lecture 5 5.1 What is UML? The Unified Modelling Language is a standard graphical

More information

Inheritance and Interfaces

Inheritance 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 information

Inheritance, Polymorphism and the Object Memory Model

Inheritance, Polymorphism and the Object Memory Model Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation

More information

#include <iostream> #include <cstdlib>

#include <iostream> #include <cstdlib> Classes and Objects Classes The structure data type can be used in both C and C++ Usually a structure is used to store just data, however it can also be used to store functions that can work on the data.

More information

C++ (Non for C Programmer) (BT307) 40 Hours

C++ (Non for C Programmer) (BT307) 40 Hours C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular

More information

Construction: High quality code for programming in the large

Construction: High quality code for programming in the large Construction: High quality code for programming in the large Paul Jackson School of Informatics University of Edinburgh What is high quality code? High quality code does what it is supposed to do......

More information

Object-Oriented Systems Analysis and Design Using UML

Object-Oriented Systems Analysis and Design Using UML 10 Object-Oriented Systems Analysis and Design Using UML Systems Analysis and Design, 8e Kendall & Kendall Copyright 2011 Pearson Education, Inc. Publishing as Prentice Hall Learning Objectives Understand

More information

Behavioral Design Patterns Used in Data Structures Implementation

Behavioral Design Patterns Used in Data Structures Implementation Behavioral Design Patterns Used in Data Structures Implementation Niculescu Virginia Department of Computer Science Babeş-Bolyai University, Cluj-Napoca email address: vniculescu@cs.ubbcluj.ro November,

More information

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued COMP322 - Introduction to C++ Lecture 09 - Inheritance continued Dan Pomerantz School of Computer Science 11 March 2012 Recall from last time Inheritance describes the creation of derived classes from

More information

Overview. OOP: model, map, reuse, extend. Examples of objects. Introduction to Object Oriented Design

Overview. OOP: model, map, reuse, extend. Examples of objects. Introduction to Object Oriented Design Overview Introduction to Object Oriented Design Understand Classes and Objects. Understand some of the key concepts/features in the Object Oriented paradigm. Benefits of Object Oriented Design paradigm.

More information

Programmazione. Prof. Marco Bertini

Programmazione. Prof. Marco Bertini Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Introduction Why OO Development? Improved structure of software easier to: Understand Maintain Enhance Reusable

More information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecturer: Raman Ramsin Lecture 15: Object-Oriented Principles 1 Open Closed Principle (OCP) Classes should be open for extension but closed for modification. OCP states that we should

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. 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 information

CS113: Lecture 4. Topics: Functions. Function Activation Records

CS113: Lecture 4. Topics: Functions. Function Activation Records CS113: Lecture 4 Topics: Functions Function Activation Records 1 Why functions? Functions add no expressive power to the C language in a formal sense. Why have them? Breaking tasks into smaller ones make

More information

17.11 Bean Rules persistent

17.11 Bean Rules persistent 17.10 Java Beans Java beans are a framework for creating components in Java. AWT and Swing packages are built within this framework Made to fit in with graphic development environments such as Jbuilder

More information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova CBook a = CBook("C++", 2014); CBook b = CBook("Physics", 1960); a.display(); b.display(); void CBook::Display() cout

More information

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011 Expanding Our Horizons CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011 1 Goals of the Lecture Cover the material in Chapter 8 of our textbook New perspective on objects and encapsulation

More information

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda

More information

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

Java Object Oriented Design. CSC207 Fall 2014

Java 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 information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecture 14: Design Workflow Department of Computer Engineering Sharif University of Technology 1 UP iterations and workflow Workflows Requirements Analysis Phases Inception Elaboration

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

3F6 - Software Engineering and Design. Handout 1 Architecture of a Computer With Markup. Ed Rosten

3F6 - Software Engineering and Design. Handout 1 Architecture of a Computer With Markup. Ed Rosten 3F6 - Software Engineering and Design Handout 1 Architecture of a Computer With Markup Ed Rosten Contents 1. Course Aims 2. Basic Computer Architecture 3. Procedural Design 4. Data Structures 5. Invariants

More information

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin Chapter 10 Object-Oriented Analysis and Modeling Using the UML McGraw-Hill/Irwin Copyright 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Objectives 10-2 Define object modeling and explain

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

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

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures)

CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures) CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures) 1. Select the best functional requirement from the list of requirements

More information

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

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation Object-Oriented Software Engineering Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized around the notion of procedures Procedural abstraction

More information

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson January 13, 2005 January 18, 2005 1 of 38 Lecture Goals Introduce the basic concepts of object-oriented analysis/design/programming

More information

History C++ Design Goals. How successful? Significant constraints. Overview of C++

History C++ Design Goals. How successful? Significant constraints. Overview of C++ 1 CS 242 History C++ John Mitchell C++ is an object-oriented extension of C C was designed by Dennis Ritchie at Bell Labs used to write Unix based on BCPL C++ designed by Bjarne Stroustrup at Bell Labs

More information

Introduction to Object- Oriented Programming

Introduction to Object- Oriented Programming Introduction to Object- Oriented Programming Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_us

More information

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

Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava Object-Oriented Genetic Improvement for Improved Energy Consumption in Google Guava Nathan Burles 1, Edward Bowles 1, Alexander E. I. Brownlee 2, Zoltan A. Kocsis 2, Jerry Swan 1, Nadarajen Veerapen 2

More information

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis UNIT I INTRODUCTION OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis Design Implementation Testing Maintenance

More information

CS 520 Theory and Practice of Software Engineering Fall 2018

CS 520 Theory and Practice of Software Engineering Fall 2018 Today CS 520 Theory and Practice of Software Engineering Fall 2018 Object Oriented (OO) Design Principles September 13, 2018 Code review and (re)design of an MVC application (and encapsulation) Polymorphism

More information

Principles of Ruby Applica3on Design. Dean Wampler Senior Mentor and Consultant Object Mentor, Inc. Chicago, IL

Principles of Ruby Applica3on Design. Dean Wampler Senior Mentor and Consultant Object Mentor, Inc. Chicago, IL Principles of Ruby Applica3on Design Dean Wampler Senior Mentor and Consultant Object Mentor, Inc. Chicago, IL dean@objectmentor.com 1 Get the latest version of this talk: aspectprogramming.com/papers

More information

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool Design Patterns What are Design Patterns? What are Design Patterns? Why Patterns? Canonical Cataloging Other Design Patterns Books: Freeman, Eric and Elisabeth Freeman with Kathy Sierra and Bert Bates.

More information

INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM

INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM Charles S. Saxon, Eastern Michigan University, charles.saxon@emich.edu ABSTRACT Incorporating advanced programming

More information

CSC207 Week 3. Larry Zhang

CSC207 Week 3. Larry Zhang CSC207 Week 3 Larry Zhang 1 Announcements Readings will be posted before the lecture Lab 1 marks available in your repo 1 point for creating the correct project. 1 point for creating the correct classes.

More information

JAVA GUI PROGRAMMING REVISION TOUR III

JAVA GUI PROGRAMMING REVISION TOUR III 1. In java, methods reside in. (a) Function (b) Library (c) Classes (d) Object JAVA GUI PROGRAMMING REVISION TOUR III 2. The number and type of arguments of a method are known as. (a) Parameter list (b)

More information

CS121/IS223. Object Reference Variables. Dr Olly Gotel

CS121/IS223. Object Reference Variables. Dr Olly Gotel CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors CS121/IS223

More information

2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature

2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature 2D1358 Object Oriented Program Construction in C++ Exercises & Labs Lecturer: Frank Hoffmann hoffmann@nada.kth.se Assistents: Danica Kragic danik @nada.kth.se Anders Orebäck oreback @nada.kth.se Peter

More information

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

Review sheet for Final Exam (List of objectives for this course) Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter

More information

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns Last Time: Object Design Comp435 Object-Oriented Design Week 7 Computer Science PSU HBG The main idea RDD: Responsibility-Driven Design Identify responsibilities Assign them to classes and objects Responsibilities

More information