Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

Similar documents
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

An Introduction To Object Modeling System Concept for Object Modeling The Overall View Components of UML Diagram

MechEng SE3 Lecture 7 Domain Modelling

Software Service Engineering

JAVA MOCK TEST JAVA MOCK TEST II

CHAPTER 5 GENERAL OOP CONCEPTS

PROGRAMMING LANGUAGE 2

Object-oriented development. Object-oriented Design. Objectives. Characteristics of OOD. Interacting objects. Topics covered

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

Representing System Architecture

UML big picture. Perdita Stevens. School of Informatics University of Edinburgh

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

administrivia today UML start design patterns Tuesday, September 28, 2010

Introduction to Object Oriented Analysis and Design

Programming Language Constructs as Basis for Software Architectures

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

1. Software Systems Complexity, OO Paradigm, UML

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Programming Language Constructs as Basis for Software Architectures. Stefan Resmerita, WS2015

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

Practical Model-Driven Development with the IBM Software Development Platform

Elementary Concepts of Object Class

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6

Ian Sommerville 2006 Software Engineering, 8th edition. Chapter 8 Slide 1

Information System Design (IT60105)

What is UML / why. UML is graphical and notational representation for software system requirements analysis and design. (Software Engineering )

UML & OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 3 09/04/2012

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

COURSE 2 DESIGN PATTERNS

OBJECT-ORIENTED MODELING AND DESIGN. Introduction

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Introduction to Software Engineering. 5. Modeling Objects and Classes

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

Class diagrams and architectural design

Chapter 5 Object-Oriented Programming

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Object-oriented Design

Object-Oriented Systems Development: Using the Unified Modeling Language

Java Object Oriented Design. CSC207 Fall 2014

Object-Oriented Systems Analysis and Design Using UML

OOAD - OBJECT MODEL. The concepts of objects and classes are intrinsically linked with each other and form the foundation of object oriented paradigm.

Introduction to Software Engineering. 5. Modeling Objects and Classes

Inheritance and Polymorphism

Object Orientated Analysis and Design. Benjamin Kenwright

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

OBJECT ORİENTATİON ENCAPSULATİON

Inheritance and Encapsulation. Amit Gupta

LABORATORY 1 REVISION

Introduction to Object-Oriented Programming

2 UML for OOAD. 2.1 What is UML? 2.2 Classes in UML 2.3 Relations in UML 2.4 Static and Dynamic Design with UML. UML for OOAD Stefan Kluth 1

Object oriented programming Concepts

Module Outline. What is Object-Oriented? Some Possible Definitions. Why Object-oriented? Fundamentals of Object Orientation

What are the characteristics of Object Oriented programming language?

For 100% Result Oriented IGNOU Coaching and Project Training Call CPD TM : ,

Modelling with Classes. CITS1220 Software Engineering

Object Fundamentals. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007

CHAPTER 1. Topic: UML Overview. CHAPTER 1: Topic 1. Topic: UML Overview

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

Object Oriented Software Development CIS Today: Object Oriented Analysis

System models Abstract descriptions of systems whose requirements are being analysed. System modelling. Structured methods

Software Testing. Lecturer: Sebastian Coope Ashton Building, Room G.18

Comp-304 : Object-Oriented Design What does it mean to be Object Oriented?

History of object-oriented approaches

Appendix A - Glossary(of OO software term s)

Object-Oriented Introduction

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

Data Structures (list, dictionary, tuples, sets, strings)

Module 10 Inheritance, Virtual Functions, and Polymorphism

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

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

Objects, Subclassing, Subtyping, and Inheritance

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

Object-Oriented Software Development Goal and Scope

1. Write two major differences between Object-oriented programming and procedural programming?

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009

Software Engineering with Objects and Components Open Issues and Course Summary

Object Oriented Paradigm

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Object-Oriented Design

Example: Fibonacci Numbers

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

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Chapter 1: Object-Oriented Programming Using C++

Programmazione. Prof. Marco Bertini

OO Requirements to OO design. Csaba Veres Alan M. Davis (1995), Colorado

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

Object-Oriented Modeling Using UML. CS151 Chris Pollett Aug. 29, 2005.

Design Pattern and Software Architecture: IV. Design Pattern

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

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

TTool Training. I. Introduction to UML

Course 3 7 March

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?

Object Oriented Concepts. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

ENCAPSULATION AND POLYMORPHISM

Transcription:

Lecturer: Sebastian Coope Ashton Building, Room G.18 E-mail: coopes@liverpool.ac.uk COMP 201 web-page: http://www.csc.liv.ac.uk/~coopes/comp201 Lecture 17 Concepts of Object Oriented Design

Object-Oriented Object orientation means to organize the software as a collection of discrete objects that incorporate both data structure and behaviour System functionality is expressed in terms of object services 2

Object Concepts We continue to explore the question what are good systems like? by describing the object oriented paradigm. We shall answer these questions: What is an object? How do objects communicate? How is an object s interface defined? What have objects to do with components? Finally we consider inheritance, polymorphism and dynamic binding. 3

Object Concepts Don t think of what an object holds but what it will do for you Consequently no public data members Think only about the methods (the public interface) Objects are potentially reusable components. An object may represent something in the real world But often not 4

What is an Object? Conceptually, an object is a thing you can interact with: you can send it various messages and it will react How it behaves depends on the current internal state of the object, which may change For example: as part of the object s reaction to receiving a message. It matters which object you interact with, an object has an identity which distinguishes it from all other objects. 5

Again What is an Object? An object is a thing which has behaviour, state and identity [Grady, Booch, 1991] Advantages: Shared data areas are eliminated. Objects communicate by message passing. Objects are independent and encapsulate state and representation information. Their independence can lead to easier maintenance 6

State The state of the object is all the data which it currently encapsulates An object normally has a number of named attributes (or instance variables or data members) each of which has a value Some attributes can be mutable (variable) An attribute ADDRESS other attributes may be immutable (constant) Date of birth Identifying number 7

Behaviour The way an object acts and reacts, in terms of its state changes as message passing. An object understands certain messages, it can receive the message and act on them. The set of messages that the object understands, like the set of attributes it has, is normally fixed. 8

Identity is more Tricky The idea is that objects are not defined just by the current values of their attributes An object has a continuous existence For example the values of the object s attributes could change, perhaps in response to a message, but it would still be the same object. 9

Example Consider an object which we ll call myclock, which understands the messages: reporttime() resettimeto(07:43), resettimeto(12:30) or indeed more generally resettimeto(newtime) How does it implement this functionality? The outside world doesn t need to know the information should be hidden but perhaps it has an attribute time Or perhaps it passes these messages on to some other object, which it knows about, and has the other object deal with messages 10

Messages A message includes a selector; here we ve seen the selectors reporttime and resettimeto A message may, but need not, include one or more arguments Often, for a given selector there is a single correct number of arguments (Recall method overloading however..) 11

Person Examples Identity Seb_Coope State Age, weight, height Behaviour setage Printer State offline, online Behaviour printdocument Sends control signals to printer Security login State Validate username, password Hash password, load credentials from database, check password 12

Interfaces The object s public interface defines which messages it will accept An object can also send to itself any message which it is capable of understanding (in either its public or private interface) So typically an object has two interfaces: The public interface (any part of the system can use) The larger private interface (which the object itself and other privileged parts of the system can use) 13

Object: Classification It depends on the abstraction level and the point of view

Object: Classification objects with the same data structure (attributes) and behaviour (operations) are grouped into a class each class defines a possibly infinite set of objects

Object: Classification Each object is an instance of a class Each object knows its class Each instance has its own value for each attribute (state) but shares the attribute names and operations with other instances of the class also static i.e. class variables A class encapsulates data and behaviour, hiding the implementation details of an object 16

Object Interface Specification Object interfaces have to be specified so that the objects and other components can be designed in parallel. Objects may have several interfaces which are viewpoints on the methods provided. Hiding information inside objects means that changes made to an object do not affect other objects in an unpredictable way. 17

Digression: Why have Classes? Why not just have objects, which have state, behaviour and identity as we require? Classes in object oriented languages serve two purposes: Convenient way of describing a collection (a class) of objects which have the same properties In most modern OO languages, classes are used in the same way that types are used in many other languages To specify what values are acceptable 18

Classes and Types Often, people think of classes and types as being the same thing (indeed it is sometimes convenient and not misleading to do so). It is not strictly correct however. Remember that a class does not only define what messages an object understands! It also defines what the object does in response to the messages. 19

What have Objects to do with Components? The hype surrounding object orientation sometimes suggests that any class is automatically a reusable component. This, of course, is not true! The first factor is that the reusability of a component is not simply a property of the component itself, it also depends upon the context of development and proposed reuse. Another important factor is that the class structure often turns out to be too fine grained for effective reuse. In order to reuse a single class you have To be writing in the same programming language and using a compatible architecture 20

Object: Inheritance Inheritance is the sharing of attributes and operations among classes based upon a hierarchical relationship A class can be defined broadly and then refined into successively finer subclasses Each subclass incorporates or inherits all of the properties of its super class and its own unique properties 21

Subclass Superclass A subclass is an extended, specialized version of its superclass. It includes the operations and attributes of the superclass, and possibly extra ones which extend the class. 22

Object: Inheritance Person Vehicle Doctor Nurse Land Vehicle Water Vehicle Surgeon Family Doctor single Car Amphibious Vehicle Boat multiple 23

Inheritance - Warning One should not abuse inheritance It is not just a way to be able to access some of the methods of the subclass A subclass must inherit all the superclass Composition is often better than inheritance (!) An object class is coupled to its super-classes. Changes made to the attributes or operations in a superclass propagate to all sub-classes. 24

Object: Polymorphism Polymorphism allows the programmer to use a subclass anywhere that a superclass is expected. E.g., if B is a subclass of type A then if an argument expects a variable of type A, it should also be able to take any variable of type B. Polymorphism essentially reduces the amount of code duplication required. However, Object-Oriented Programming Languages also usually have a feature called dynamic binding which makes this idea even more useful.. 25

Dynamic Binding Dynamic Binding is when an object determines (possibly at run time) which code to execute as the result of a method call on a base type. For example, imagine C is a subclass of B and both have a method named printname(). Then if we write: B temp = new C(); // (This is allowed by polymorphism) temp.printname(); we would invoke the printname() method of object C, not of object B, even though the type of temp is B. This is dynamic binding. Let us consider another example.. 26

Dynamic Binding - Example Vehicle v = null; v = new Car(); v.startengine(); v = new Boat(); v.startengine(); Call Car startengine() method Call Boat startengine() method 27

Unified Modelling Language(UML) Unify notations UML is a language for: Specifying Visualizing and Documenting the parts of a system under development Authors (Booch, Rumbaugh and Jacobsen) agreed on notation but not able to agree on a single method This is probably a good thing UML has been adopted by the Object Management Group (OMG) as an Object-Oriented notation standard 28

UML Other Influences Meyer pre and post conditions Harel - statecharts Wirfs-Brock - responsibilities Coleman - message numbering scheme Embley - singleton classes Gamma - patterns, notes Shlaer, Mellor - object lifecycles 29

UML Some Notation Object classes are rectangles with the name at the top, attributes in the middle section ( compartment ) and operations in the next compartment. Relationships between object classes (known as associations) are shown as lines linking objects Inheritance is referred to as generalisation. It uses an open triangular arrow head 30

Library System UML Example Note that if you avoid Generalisation you have a recognisable ER diagram 31

CASE Tools/Workbenches Computer Aided Software Engineering (CASE) A coherent set of tools to support a software engineering method These workbenches may support a specific SE method or may provide support for creating several different types of system model. There are also meta-case tools A CASE tool to build CASE tools 32

CASE Tool Components Diagram editors Model analysis and checking tools Repository and associated query language Data dictionary Report definition and generation tools Forms definition tools Code generation tools Import/export translators 33

Key Points Object Oriented Design is an approach to design so that design components have their own private state and operations. Objects should have a constructor as well as inspection operations. They provide services to other objects. Objects may be implemented sequentially or concurrently. 34

Key Points Object interfaces should be defined precisely using e.g. a programming language like Java. Object-oriented design potentially simplifies system evolution. The Unified Modeling Language provides different notations for defining different object models. 35