James Tam Object-Oriented Design Approaches to object-oriented design Some principles for good design Benefits and Drawbacks of the Object-Oriented Approach.

Slides:



Advertisements
Similar presentations
1) Scope a] Ada scope rules b] C scope rules 2) Parameter passing a] Ada parameter modes b) Parameter passing mechanisms COMP205 IMPERATIVE LANGUAGES 13.
Advertisements

Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Inheritance Inheritance Reserved word protected Reserved word super
James Tam CPSC 233: Introduction to Classes and Objects, Part I Attributes and methods Creating new classes References: Dynamic memory allocation and.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
1 Chapter 7 User-Defined Methods Java Programming from Thomson Course Tech, adopted by kcluk.
J. Michael Moore Software Design CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Object-Oriented Design And Software Testing In this section of notes you will learn about principles of good design as well how testing is an.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
James Tam Object-Oriented Principles in Java: Part I Encapsulation Information Hiding Implementation Hiding Creating Objects in Java Class attributes.
James Tam Object-Oriented Design And Software Testing In this section of notes you will learn about principles of good design as well how testing is an.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
18-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Objects and Classes (cont)
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
5.1 and 5.4 through 5.6 Various Things. Terminology Identifiers: a name representing a variable, class name, method name, etc. Operand: a named memory.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
James Tam Advanced Java Programming After mastering the basics of Java you will now learn more complex but important programming concepts as implemented.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
INT-Evry (Masters IT– Soft Eng)IntegrationTesting.1 (OO) Integration Testing What: Integration testing is a phase of software testing in which.
University of Toronto Department of Computer Science CSC444 Lec05- 1 Lecture 5: Decomposition and Abstraction Decomposition When to decompose Identifying.
CSC 212 Object-Oriented Programming and Java Part 1.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
CSE 219 Computer Science III Program Design Principles.
Introduction to Computers and Programming Lecture 14: User defined methods (cont) Professor: Evan Korth New York University.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
1 CSC241: Object Oriented Programming Lecture No 25.
Vladimir Misic: Characters and Strings1Tuesday, 9:39 AM Characters and Strings.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
Object-Oriented Design Concepts University of Sunderland.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Object-Oriented Programming (OOP) and C++
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Fall 2013 Chapter 10 Thinking.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Chapter 10 Thinking in Objects
Chapter 7 User-Defined Methods.
Types for Programs and Proofs
Chapter 10 Thinking in Objects
Chapter 10 Thinking in Objects
Data Abstraction: The Walls
Topic: Functions – Part 2
About the Presentations
(5 - 1) Object-Oriented Programming (OOP) and C++
Chapter 9 Thinking in Objects
Chapter 6 Methods: A Deeper Look
Group Status Project Status.
Chapter 9 Thinking in Objects
(5 - 1) Object-Oriented Programming (OOP) and C++
Week 4 Lecture-2 Chapter 6 (Methods).
COP 3330 Object-oriented Programming in C++
Java Methods: A Deeper Look Academic 2019 Class: BIT23/BCS10 Chapter 06 Abdulaziz Yasin Nageye Faculty of Computing Java How to Program, 10/e 1 © Co py.
Presentation transcript:

James Tam Object-Oriented Design Approaches to object-oriented design Some principles for good design Benefits and Drawbacks of the Object-Oriented Approach

James Tam A Model For Creating Computer Software Specify the problem i.e., Determine what problem do we wish to solve Determine how to solve the problem Designing a system to solve the problem (plan) Implement the solution Writing up a solution in the chosen application language Maintenance of the solution Fixing bugs, implementing new features

James Tam A Model For Creating Computer Software Specify the problem i.e., Determine what problem do we wish to solve Determine how to solve the problem Designing a system to solve the problem (plan) Implement the solution Writing up a solution in the chosen application language Maintenance of the solution Fixing bugs, implementing new features

James Tam Approaches To Object-Oriented Design Traditional techniques Finding the nouns Using CRC cards Currently used techniques Apply object decomposition Examine similar systems This list is by no means complete but provides a starting point for students who are new to the Object-Oriented approach

James Tam Finding The Nouns Mummy Scorpion Dragon Screamer Ghost Knight Monsters Weapons Armour Broadsword Longbow Rapier Dungeon Master :

James Tam Finding The Nouns:Approach 1.Obtain a description of the problem to be solved 2.Identify the nouns in the document in order to look for candidate classes 3.Identity the verbs in the document in order look for potential methods

James Tam Finding Nouns: Discussion Advantage Requires no training, easy to apply Drawback There is not always a direct mapping between nouns and classes

James Tam Using CRC (Class-Responsibility- Collaboration) Cards Display collectionBook Add a new book Remove a book Update book info. CollectionManager List of books in the collection ResponsibilitiesCollaborations

James Tam Using CRC Cards: Approach 1.Obtain a description of the system to be modeled 2.On the front of the CRC card (cardboard or sticky note) state the name of the class and list it’s responsibilities and collaborations 3.On the back of the card list the attributes of the class 4.Pass the completed deck of cards to experienced developers to look for holes in the deck

James Tam Using CRC Cards: Discussion Advantage: Relatively simply to learn and apply Having the cards examined by experts may result in fewer gaps than just finding the nouns Disadvantage: More useful for defining rather than identifying classes (should already have a list of classes)

James Tam Combining Techniques 1)Use the “find the nouns” approach to derive a list of candidate classes 2)Analyze this list by employing the CRC technique

James Tam Applying Object Decomposition Dungeon Dungeon Master Dungeon level Dungeon walls

James Tam Applying Object Decomposition: Approach 1.Obtain a description of the system to be modeled 2.Find the aggregate categories of classes 3.Decompose the categories in order to identify their components 4.Continue the process of decomposition until you reach the bottom level classes

James Tam Applying Object Decomposition: Discussion Advantages A natural approach for dealing with aggregates Disadvantages Not all classes are components of an aggregate More useful for describing how classes are related rather than indicating how to derive a list of classes

James Tam Examining Similar Systems

James Tam Examining Similar Systems: Approach It can be done in a number of ways: 1.Look at how similar systems were implemented (whole systems) 2.Examine existing code libraries for reusable code (portions) 3.Using personal experience

James Tam Some Principles Of Good Design Avoid going “method mad” Keep an eye on your parameter lists Avoid real values when an integer will do Minimize modifying immutable objects Be cautious in the use of references Consider where you declare local variables This list was partially derived from “Effective Java” by Joshua Bloch and is by no means complete. It is meant only as a starting point to get students thinking more about why a practice may be regarded as “good” or “bad” style.

James Tam Avoid Going Method Mad There should be a reason for each method Creating too many methods makes a class difficult to understand, use and maintain A good approach is to check for redundancies

James Tam Keep An Eye On Your Parameter Lists Avoid long parameter lists Rule of thumb: Three is the maximum Avoid distinguishing overloaded methods solely by the order of the parameters

James Tam Avoid Real Values When An Integer Will Do double db = ; if (db == 0.61) System.out.println("Sixty one cents"); System.out.println(db);

James Tam Minimize Modifying Immutable Objects Immutable objects Once instantiated they cannot change e.g., String s = "hello"; s = s + " there";

James Tam Minimize Modifying Immutable Objects (2) Substitute Immutable objects with mutable ones e.g., Class StringBuffer { public StringBuffer (String str); public StringBuffer append (String str); : : : : } For more information about this class

James Tam Minimize Modifying Immutable Objects (3) class StringExample { public static void main (String [] argv) { String s = "0"; for (int i = 1; i < 10000; i++) s = s + i; } class StringBufferExample { public static void main (String [] argv) { StringBuffer s = new StringBuffer("0"); for (int i = 1; i < i++) s = s.append(i); }

James Tam Be Cautious In The Use Of References Similar to global variables: program globalExample (output); var i : integer; procedure proc; begin for i:= 1 to 100 do; end; begin i := 10; proc; end.

James Tam Be Cautious In The Use Of References (2) class Foo { private int num; public int getNum () {return num;} public void setNum (int no) {num = no;} }

James Tam Be Cautious In The Use Of References (3) class Driver { public static void main (String [] argv) { Foo f1, f2; f1 = new Foo (); f1.setNum(1); f2 = f1; f2.setNum(2); System.out.println(f1.getNum()); System.out.println(f2.getNum()); }

James Tam Consider Where You Declare Local Variables First Approach: Declare all local variables at the beginning of a method: void methodName (..) { int num; char ch; : } Advantage: Putting all variable declarations in one place makes them easy to find

James Tam Consider Where You Declare Local Variables (2) Second Approach: declare local variables only as they are needed void methodName (..) { int num; num = 10; : char ch; ch = ‘a’; } Advantage: For long methods it can be hard to remember the declaration if all variables are declared at the beginning Reducing the scope of a variable may reduce logic errors

James Tam Common Reasons Given For Adopting The Object- Oriented Approach It's the latest thing, isn't it? I read about it in Business Week My boss's boss read about it in Business Week I think our competitors are using it Three of us went to a talk by Bertrand Meyer and we're really enthused Structured techniques don't work Extracted from:

James Tam Benefits Of Object-Orientation May be more intuitive for some types of applications Provides mechanisms for more robust programs Fewer bugs Allow for more code reuse Easier to maintain and modify programs

James Tam Drawbacks Of Object-Orientation Programs tend to be larger Typically a steeper learning curve than with procedural languages

James Tam Summary What are some traditional and modern approaches to Object-Oriented design Finding the nouns Using CRC cards Applying object decomposition Examining similar systems A sample list of good design principles in Java Avoid going “method mad” Keep an eye on your parameter lists Avoid real values when an integer will do Minimize modifying immutable objects Be cautious in the use of references Consider where you declare local variables What are some of the benefits and drawbacks of the Object-Oriented approach