Week 5: Class Design Concepts fundamental to the class design Encapsulation & Information hiding Analyzing the quality of an interface Programming by contract.

Slides:



Advertisements
Similar presentations
Addressing the Challenges of Current Software. Questions to Address Why? What? Where? How?
Advertisements

SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
David Woo (dxw07u).  What is “White Box Testing”  Data Processing and Calculation Correctness Tests  Correctness Tests:  Path Coverage  Line Coverage.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
Chapter 3 (Horstmann’s Book) Guidelines for Class Design Hwajung Lee.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Software Testing and Quality Assurance
1 Objectives To introduces the concept of software Design. To introduce the concept of Object- Oriented Design (OOD). To Define various aspects about object.
Illinois Institute of Technology
1 Class design guidelines. 2 Encapsulation Classes can be implemented many different ways –each has advantages & disadvantages –improvement/revision always.
Chapter 1 Principles of Programming and Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
SOFTWARE QUALITY ASSURANCE Maltepe University Faculty of Engineering SE 410.
Introduction To System Analysis and design
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CMSC 345 Fall 2000 Unit Testing. The testing process.
Software Testing.
The Program Development Cycle
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Testing Workflow In the Unified Process and Agile/Scrum processes.
Computer Concepts 2014 Chapter 12 Computer Programming.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles Modified from the Slides made by Sylvia Sorkin, Community College of Baltimore.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Systems Analysis and Design in a Changing World, 3rd Edition
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
Chapter 3 Guidelines for Class Design. Objective of this chapter Have “bottom up point of view” Learn how to write a single class well.  The classes.
Abstraction ADTs, Information Hiding and Encapsulation.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Introduction to Object-Oriented Programming Lesson 2.
Software Testing and Quality Assurance 1. What is the objectives of Software Testing?
Software Engineering Issues Software Engineering Concepts System Specifications Procedural Design Object-Oriented Design System Testing.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
Testing i. explain the importance of system testing and installation planning;
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Principles of Programming & Software Engineering
ITEC324 Principle of CS III
CSE 219 Final exam review.
Software Testing.
C++ Plus Data Structures
Chapter ? Quality Assessment
Software Engineering (CSI 321)
Levels of testing.
Testing Object-Oriented Programs
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
Types of Testing Visit to more Learning Resources.
Chapter 1 Software Engineering.
CSC 480 Software Engineering
Subprograms and Programmer Defined Data Type
Lecture 09:Software Testing
Verification and Validation Unit Testing
Chapter 10 – Software Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Software Testing “If you can’t test it, you can’t design it”
CMPE 135: Object-Oriented Analysis and Design February 21 Class Meeting Department of Computer Engineering San Jose State University Spring 2019 Instructor:
Presentation transcript:

Week 5: Class Design Concepts fundamental to the class design Encapsulation & Information hiding Analyzing the quality of an interface Programming by contract Software & Unit testing 1 Object-oriented Software Design

2 Fundamental Design Concepts 1/3 l Abstraction nAbstraction is an important simplifying technique enabling us to replace a complex and detailed real world situation with a model within which we can solve a problem. nIn OO software design o We produce an abstraction of the software system to be built using a set of use cases, classes & their relationships, sequence diagrams and state diagrams, among others. oBuilt-in data types and programmer-defined classes are abstractions that describe data objects with states oFunction/Method represents an action or a service to be provided oControl: a control mechanism without specifying internal details, e.g. a sequence diagram, or Remote Method Invocation (RMI)

3 Fundamental Design Concepts 2/3 l Encapsulation nAs a process, encapsulation means the act of enclosing one or more items within a physical or logical container, as an entity nEncapsulation refers to the package or enclosure that holds one or more items. nIn procedural programming oa function/module perform a task/functionality oexamples? nIn object-oriented programming oa class encapsulates both data and operations oexamples?

4 Fundamental Design Concepts 3/3 l Information Hiding nSeparation of interface and implementation oSoftware components can be developed in isolation from each other. oAlso good for re-use. nThe computer scientist David Parnas expressed these ideas in a pair of rules known as Parna's Principles oThe developer of a software component must provide the intended user with the information needed to make effective use of the services provided by the component, and should provide no other information. oThe developer of a software component must be provided with all the information necessary to carry out the given responsibilities assigned to the component, and should be provided with no other information. nNotes: While Encapsulation is design-related, Information hiding – implementation-related. However, some authors do not distinguish the meanings of “encapsulation” and “information hiding”. This could imply that information hiding seems to be an attribute of encapsulation.

5 Applying the concepts to class design l A class can be an abstraction of a type of real world objects nshapes ncars nPeople nAccount Payable service l The class code encapsulates both ndata nfunctions/methods/operation l Good class design hides away its implementation details nprivate/protected/public ndata members can only be accessed by Setter and Getter nIt implies that the same class design may be implemented in more than one way, which doesn’t affect the user/client of the class.

6 How to achieve Encapsulation and Information hiding by class design & implementation l Quality of Class Interface l Programming by Contract l Use of Assessors and Mutators l Avoiding side effects

7 Quality of Class Interface l Customers/Clients are Programmers using the class nThey are unaware of implementation nThe class designer/programmer should make no assumption re. the customer knowing of implementation details l Criteria: nCohesion: oClass describes a single abstraction oMethods should be related to the single abstraction nCompleteness oSupport operations that are well-defined on abstraction nConvenience nClarity oDesign should be intuitive and following the user’s mental model nConsistency l Engineering activity: make tradeoffs

8 Programming by Contract l Spell out responsibilities using pre- & post-conditions n of caller (preconditions) nof implementer ((postconditions) nThat would increase reliability and efficiency l Preconditions nExcessive error checking is costly nReturning dummy values can complicate testing nContract metaphor oService provider must specify preconditions oIf precondition is fulfilled, service provider must work correctly oOtherwise, service provider can do anything nWhen precondition fails, service provider may othrow exception oreturn false answer ocorrupt data l Postconditions nConditions that the service provider guarantees nEvery method promises nSometimes, can assert additional useful condition

9 Accessors and Mutators l Mutator: Changes object state nE.g. Setter methods of a class l Accessor: Reads object state without changing it nE.g. Getter methods of a class l Class without mutators is immutable nJava String class is immutable nDate and GregorianCalendar are mutable l Sharing Mutable References nReferences to immutable objects can be freely shared nDon't share mutable references  To avoid: use clone( ) method in Java or final static field in declaration

10 Side Effects l Accessor: no change to object l Mutator: changes object state l Side effect: change to another object nParameter variable nstatic object l Avoid side effects--they confuse users l Law of Demeter nThe law: A method should only use objects that are oinstance fields of its class oparameters oobjects that it constructs with new nShouldn't use an object that is returned from a method call Remedy in mail system: Delegate mailbox methods to mail system mailSystem.getCurrentMessage(int mailboxNumber); mailSystem.addMessage(int mailboxNumber, Message msg);... nJust a rule of thumb, not a mathematical law

11 Software Testing Strategies and Techniques l While the techniques of modular software design is top- down, the testing is bottom-up. Acceptance Testing System Testing Validation Testing Integration Testing Unit/module Testing (programmers) (Testers) (at developer’s site) (by users/customers) (to test smallest components) (to test group of units, unit interfaces) (to test requirement specs) (to test the whole system in an actual operating environment)

12 Software testing techniques 1/2 l Different testing techniques are used at the different testing stages. They can be categorised broadly into white box and black box testing. l Back box testing nThe software is treated like a black box nBlack box testing is performed by creating test data according to the requirements specification, and the expected results, then testing the software using the prepared tests, and comparing the expected results with the actual results. nAs well as establishing whether or not the software is correct, black box testing can result in changed functionality etc. to be more user friendly.

13 Software testing techniques 2/2 l White box testing nWhite box testing is the testing of the correctness of the software itself. The most important part of the testing process is to ensure that the tests have been properly designed so as to test all the paths, all the conditions rather than the same one every time. nThe basis path analysis, which is based on McCabe cyclomatic complexity metric, is a well-established white box testing technique. nModule Integration Testing where a group of modules is tested e.g. a module and its immediate subordinates nUnit testing can be performed using driver programs, or skeleton programs in which each unit would initially exist as a stub, and then inserted to replace the stub to be tested within the skeleton program.

14 Unit testing with JUnit nJUnit is an increasingly popular tool for unit testing nA tutorial and more details can be found at nTest class name = tested class name + Test nTest methods start with test import junit.framework.*; public class DayTest extends TestCase { public void testAdd() {... } public void testDaysBetween() {... }... } nEach test case ends with assertion nTest framework catches assertion failures public void testAdd() { Day d1 = new Day(1970, 1, 1); int n = 1000; Day d2 = d1.addDays(n); assert d2.daysFrom(d1) == n; }

15 Summary nFundamental design concepts oabstraction oencapsulation oinformation hiding nClass design techniques oDesign “good” class interface oProgramming by contract oUse of assessors & mutators oAvoid side effects nSoftware & unit testing