MechEng SE3 Lecture 7 Domain Modelling

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

Introduction to Software Engineering. 5. Modeling Objects and Classes

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

Software Service Engineering

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

Software Engineering Lab Manual

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

UML Primer. -Elango Sundaram

Inheritance and Polymorphism

Introducing the UML Eng. Mohammed T. Abo Alroos

Object Oriented Software Development CIS Today: Object Oriented Analysis

UML: Unified Modeling Language

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

Data Abstraction. Hwansoo Han

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

Object Orientated Analysis and Design. Benjamin Kenwright

Object Oriented Modeling

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

LABORATORY 1 REVISION

Goals of the Lecture OO Programming Principles

Object-oriented basics. Object Class vs object Inheritance Overloading Interface

Object-Oriented Analysis and Design Using UML (OO-226)

Introduction to Software Engineering. 5. Modeling Objects and Classes

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

Experiment no 4 Study of Class Diagram in Rational Rose

OBJECT ORİENTATİON ENCAPSULATİON

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Basic Object-Orientation

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

In this Lecture you will Learn: Design Patterns. Patterns vs. Frameworks. Patterns vs. Frameworks

Inheritance, and Polymorphism.

CS1004: Intro to CS in Java, Spring 2005

OO Techniques & UML Class Diagrams

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

06. Analysis Modeling

CSCU9T4: Managing Information

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 5: Modelling with Classes

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

OO Analysis and Design with UML 2 and UP

University of Calgary Department of Electrical and Computer Engineering. SENG : Object Oriented Analysis and Design Behrouz Homayoun Far

Introduction to Object-Oriented Programming

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

Object-Oriented Systems Analysis and Design Using UML

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

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

Course 3 7 March

MSc programme (induction week) Department of Informatics INTRODUCTION TO UML

UML diagrams. Software artifacts include: SRS, SDS, test cases, source code, technical/user manual, software architecture, etc.

1 OBJECT-ORIENTED ANALYSIS

Unified Modeling Language

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

Chapter 2, Modeling with UML, Part 2

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

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

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

Appendix A - Glossary(of OO software term s)

Unified Modeling Language (UML) Class Diagram

CS 1316 Exam 1 Summer 2009

What are the characteristics of Object Oriented programming language?

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

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

Introduction to Unified Modelling Language (UML)

Chapter : Analysis Modeling

INTRODUCTION TO UNIFIED MODELING MODEL (UML) & DFD. Slides by: Shree Jaswal

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

Unit Wise Questions. Unit-1 Concepts

MSO Analysis & UML. Hans Philippi (based on the course slides of Wouter Swierstra) August 24, Analysis & UML 1 / 56

ITI Introduction to Computing II

Software Design Models, Tools & Processes. Lecture 3: Addendum Cecilia Mascolo

CS112 Lecture: Defining Instantiable Classes

CS121/IS223. Object Reference Variables. Dr Olly Gotel

ECE 122. Engineering Problem Solving with Java

user.book Page 45 Friday, April 8, :05 AM Part 2 BASIC STRUCTURAL MODELING

Lecture 7: Classes and Objects CS2301

ITI Introduction to Computing II

Software Engineering from a

OO System Models Static Views

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

UML Modeling I. Instructor: Yongjie Zheng September 3, CS 490MT/5555 Software Methods and Tools

CS445 Week 9: Lecture

Objectives. Explain the purpose and objectives of objectoriented. Develop design class diagrams

Java Object Oriented Design. CSC207 Fall 2014

CISC 322 Software Architecture

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

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

Object-Oriented Analysis and Design

Object-Oriented Programming Paradigm

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

CHAPTER 9 DESIGN ENGINEERING. Overview

Software Development Cycle. Unified Modeling Language. Unified Modeling Language. Unified Modeling Language. Unified Modeling Language.

Ingegneria del Software Corso di Laurea in Informatica per il Management. Introduction to UML

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

Chapter 13. Object Oriented Programming

Chapter 1: Principles of Programming and Software Engineering

Week. Lecture Topic day (including assignment/test) 1 st 1 st Introduction to Module 1 st. Practical

Inheritance and Interfaces

Notation Part 1. Object Orientated Analysis and Design. Benjamin Kenwright

Building custom components IAT351

Transcription:

MechEng SE3 Lecture 7 Domain Modelling Simon Gay (slides by Phil Gray) 17 February 2010 1

This week s supplementary reading Zero Balances and Zero Responsibility Michael Bolton http://www.developsense.com/essays/zero.html 2

Where to go for more Sommerville, 7 th & 8 th editions. Section 8.4, Chap 14 (especially 14.1 and 14.2.3) 3

What is object-oriented programming? Imagine that we want to work with shapes: squares, circles, rectangles etc. Calculating the area of a shape is important. In a programming language, we can define functions to calculate the areas of various shapes. 4

Shape calculations in Python def squarearea(side):! return side*side! def rectanglearea(width,height):! return width*height! def circlearea(radius):! return pi*radius*radius! Within a program, squarearea(4) evaluates to 16. 5

Shapes in Java class Square {! int side;! class Rectangle {! int width,height;! }! Square(int x) {! side = x;! }! int area() {! return side*side;! }! }! Rectangle(int x, int y) {! width = x;! height = y;! }! int area() {! return width*height;! }! 6

Shapes in Java Within a program: Square s = new Square(4);! and then s.area() evaluates to 16. 7

Shapes in Java Other properties of shapes, for example position, colour, can be stored in the same way as the lengths of the sides. Other functions (methods) can be defined in the same way as area. We can go further by explicitly showing that Square, Circle, Rectangle have something in common: they are all shapes. 8

Shapes in Java abstract class Shape {! int area();! }! class Rectangle! extends Shape {! int width,height;! class Square extends Shape {! int side;! }! Square(int x) {! side = x;! }! int area() {! return side*side;! }! }! Rectangle(int x, int y) {! width = x;! height = y;! }! int area() {! return width*height;! }! 9

Shapes in Java Now, if s is any object of class Shape, we can use s.area() and the area will be calculated by the method definition in the particular class that s belongs to. 10

Shapes in Java Finally, imagine that a picture contains a list of shapes: class Picture {! List<Shape> shapes;! Picture(List<Shape> sh) {! shapes = sh;! }! }! int area() {! int a = 0;! for (Shape s : shapes)! a = a + s.area();! return a;! }! 11

A little history: programming languages Simula» Late 1960s» a language for developing simulations» encapsulation Smalltalk» 1970s» GUI concepts» Strictly object-oriented» untyped» Garbage collection C++» 1980s» Extensions to existing GPL Java» 1990s» typed» Not an extension of previous language» Features for web-based applications C#» 2000» Designed for service-based distributed applications 12

A little history: modelling Object-oriented modelling grew up in the 1980s» Grady Booch, 1982, Object-Oriented Design» Jim Rumbaugh, OMT (object modelling technique)» Ivor Jacbosen, Objectory Method UML» Booch & Rumbaugh combine in 1994, later joined by Jacobsen» The Three Amigos» Formed The Rational Corporation Recently absorbed into IBM UML now managed as a standard by OMG» UML 1.0 in 1997» Now UML 2.0 13

Objects and Classes An object is» a computational entity which provides services with which other entities may interact typically, the service consumer sends a message (requesting the service) to the provider object» possesses State Behaviour Identity 14

Classes A class» Describes a set of equivalent objects hence, operates like a data type for objects typically, every object in a system belongs to a class» Provides a useful way of representing and implementing the shared state and behaviour of the objects that it describes E.g., object creation method 15

Sommerville on Objects Object is an entity that has a state and a set of operations on that state. The state is represented as a set of object attributes. The operations associated with the object provide services to other objects (clients) that request these services when some computation is required. (section 14.1) 16

Why Objects? Encapsulation Objects can operate as software modules that organise data and behaviour into meaningful associations Message-based Invocation Helps to make code adaptable and reusable, since» receivers don t have to know about senders» senders need only know about message protocol for receivers» Hence message protocol is a well-defined interface between senders and receivers Data Hiding Data hiding helps to manage complexity, since programmer can control the data that objects are allowed to do manipulate 17

Data Hiding Object technology (e.g., object-oriented programming languages and databases) provide mechanisms for controlling access to attributes So, attributes can be private to the owning object or to some restricted set of objects An sender can query or modify an attribute of a receiver via appropriate messages, even if the attribute is private 18

Sommerville on Classes Objects are created according to an object class definition. An object class definition is both a type specification and a template for creating objects. It includes declarations of all the attributes and operations that should be associated with an object of that class. (section 14.1) 19

Why Classes? Inheritance» Provides a mechanism for sharing attributes and operations,» a form of reuse Polymorphism» Allows different effects of messages to be determined by the receiver, without the sender having to know about the differences» And, can add new (sub)classes of objects without having to change the interface between sender and receiver 20

Method Classification There are three different types of method constructor» It will be called when an object is created» It provides guaranteed initialisation A transformer» which changes the internal state of the object An accessor» which uses the internal data without changing it ("method", "message" and "operation" mean the same thing) 21

Where do classes come from? once we have a set of use cases we begin a process of analysis to identify candidate data that participates in the use cases the types for this data will become a set of classes during design we will» refine these class definitions» add additional classes as necessary 22

Analysis vs Design In developing our understanding of the classes needed for a proposed system, there are two fundamental stages: analysis & design According to Larman (Applying UML & Patterns, section 1.4):» Analysis: During object-oriented analysis, there is an emphasis on finding and describing objects (or concepts) in the problem domain.» Design: During object-oriented design, there is an emphasis on defining software objects and how they collaborate to fulfill the requirements. This lecture focusses on (early) analysis 23

Class Notation in UML A class is represented by a rectangle with three compartments.» The name of the class» The class attributes» The class operations. The attributes are listed in a language dependent way. UML is not fussy about the notation used. The operations are written in the same language style as the attributes. 24

Naming Classes and Instances AClass :AClass a class an anonymous instance of AClass a1:aclass a named instance of AClass ASuperClass::AClass refers to AClass which inherits from ASuperClass 25

Levels of Class Description Consider class that represents student information" Analysis" Student has a name attribute" High level design" Student name getname() setname() 26

Levels of Class Description Detailed design"» Attribute held as Student private member?"» Or implemented as instance of a new Name class?" Implementation" Class Student { private String name; public String getname(); public setname(); } -name : String +getname():string +setname(string) 27

An Example Use Case: Add New Lecture to Module Lecturer Add a new lecture to a module 28

An Example Use Case: Add New Lecture to Module The lecturer selects the required module from the relevant course and adds a new lecture to the existing list of lectures for that module. The details of the lecture are completed by the lecturer." 29

An Example Use Case: Add New Lecture to Module The lecturer selects the required module from the relevant course and adds a new lecture to the existing list of lectures for that module. The details of the lecture are completed by the lecturer." 30

CRC: Finding Classes CRC=Class-Responsibility-Collaboration Technique for capturing initial class information Use index cards, one per candidate class Keep descriptions informal and simple 31

CRC Format Class Name Responsibilities Collaborations 32

CRC for Campaign Class Name: Module Responsibilities Provide list of lectures Add a new lecture Collaborations Course Lecture 33

Class Responsibilities Doing» Doing something itself» Starting an action in another object» Coordinating other objects Knowing» Knowing private data» Knowing about related objects» Knowing how to derive a value 34

Finding Collaborations Class Name: Module Class Name: Lecture Responsibilities Provide list of lectures Add a new lecture Collaborations Responsibilities Provide lecture details Construct new lecture Collaborations Provide lecture detail editing Edit lecture details Class Name: Course Responsibilities Provide module list Select a module Collaborations 35

Elaborating the Classes Each class has!» A set of attributes» A set of operations» A set of associations We represent this information in a class diagram 36

Class Diagram Structure class name attributes operations 37

Naming the Class Module attributes operations 38

Attributes Module title operations info needed to select module 39

Operations Module title getlectures() addlecture() setlecturedetails() Gives the lecture list 40

Associations title Module getlectures() addlecture() setlecturedetails() includes 1 0..* title Lecture setdetails() 41

Kinds of Associations Module Module Course 1 1 1 0.. * * 1..8 Timetable Lecture Module Staff Member 1 * manages 42

Representing Associations between Instances and between Classes Sometimes it s useful, especially in early analysis stages, to examine associations at the level of object instances Later, as the classes are being identified and specified, associations are represented at the class level 43

Representing Associations between Instances and between Classes Module 1 0.. * Lecture lect1: Lecture :Module lect2: Lecture lect3: Lecture 44

Aggregates and Composites Aggregate» an association in which one object is a part of another» Shown by an open diamond at aggregation end Composition» a strong form of aggregation» If the composite is deleted or copied, so must its parts be» Shown with a filled diamond at the composite end 45

Examples Course 1.. * 1..8 Module ChessBoard 1 64 Square 46

Class Diagram from Example Use Case Module 1 1.. * Lecture title title getlectures() addlecture() setlecturedetails() setdetails() 1..8 * title Course getmodules() selectmodule() 47

Finding Attributes Attributes should be atomic or simple» boolean, data, number, string, time A proposed attribute may turn out to be an association with another object Derive attributes from operations» If you have a "provide name" operation, then you will need a name attribute or an association with a name 48

Finding Attributes in Our Example Consider setlecturedetails The use case as it stands does not specify the attributes that make up the lecture details Thus, the analysis may raise questions about the completeness or clarity of the use case description E.g., perhaps need to go back to client or to domain stakeholders to determine what is needed as lecture attributes 49

Referring to associated objects At the analysis stage, you do not need to» indicate how an association will be implemented» decide how to represent a collection That will be determined later in the design process 50

Another Example: Assign Lecturer to a Module Actor Action System Response Selects course Selects module Selects staff member to be assigned to this module Lists titles of all courses Lists titles of all modules for that course Displays all staff members not already allocated to a module Displays confirmation 51

Class Diagram from First Use Case Module 1 1.. * Lecture title title getlectures() addlecture() setlecturedetails() setdetails() 1..8 * title Course getmodules() selectmodule() 52

Refining the Class Diagram (1) Course Module Lecture 53

Refining the Class Diagram (2) Courses Course Module Lecture 54

Refining the Class Diagram (4) Courses Staff Course Module StaffMember Lecture 55

Visibility Visibility is related to the data hiding features of class members + public (external code can use) # protected (only child classes can use) - private (internal to class) Private is normally only useful at the implementation level Protected is related to inheritance and will be discussed later 56

Visibility Something to think about: How is visibility handled in Java? Compare it to the visibility feature in UML 57