1 Working with Classes Chapter 6. 2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide.

Slides:



Advertisements
Similar presentations
Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday.
Advertisements

Data Structures.
Software Engineering Class design. Class design – ADT Abstract Data Types:  Why use ADT? Hidden implementation details Changes do not affect whole program.
Programming Logic and Design Fourth Edition, Introductory
Software Engineering and Design Principles Chapter 1.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Object-oriented Programming Concepts
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Lecture 9 Concepts of Programming Languages
Data Abstraction: The Walls
Chapter 22 Object-Oriented Design
Computer Science 240 Principles of Software Design.
Introduction - The Need for Data Structures Data structures organize data –This gives more efficient programs. More powerful computers encourage more complex.
The Unified Modeling Language (UML) Class Diagrams.
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
The Pseudocode Programming Process Chapter 9. Summary of Steps in Building Classes and Routines.
The Design Discipline.
Chapter 5CSA 217 Design in Construction Chapter 5 1.
Introduction to Object-oriented programming and software development Lecture 1.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Chapter 3 Introduction to Collections – Stacks Modified
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Computer Science 240 © Ken Rodham 2006 Principles of Software Design.
Introduction To System Analysis and Design
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
1 Software Design Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13, 5 th edition and Ch. 10, 6 th edition.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
1 Software Design Overview Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13.
SE: CHAPTER 7 Writing The Program
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Good Design of Classes Classes let us create Abstract Data Types Should be well aware of benefits – Hide implementation details – Localize changes – Interface.
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
Linked List. Iterators Operation to find a link, deleting, and inserting before or after a specified link, also involve searching through the list to.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Data Abstaraction Chapter 10.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
Learners Support Publications Object Oriented Programming.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Stack.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Working Classes SCMP Special Topic: Software Development
Sections 3.4 Formal Specification
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Programming Logic and Design Seventh Edition
Data Abstraction: The Walls
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Lecture 22 Inheritance Richard Gesick.
LESSON 13 – INTRO TO ARRAYS
ITEC 2620M Introduction to Data Structures
Software Design Lecture : 9.
Lecture 9 Concepts of Programming Languages
Presentation transcript:

1 Working with Classes Chapter 6

2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide provides a cohesive set of services. A class is a collection of data and routines that share a well-defined responsibility or provide provides a cohesive set of services. As programmer, you can ignore the rest of program while you are working on any part of code. This is accomplished by implementing classes As programmer, you can ignore the rest of program while you are working on any part of code. This is accomplished by implementing classes

3 Abstract Data Types (ADTs) Understanding ADTs is essential to understanding object-oriented programming Understanding ADTs is essential to understanding object-oriented programming ADT is a collection of data and operations that work on that data ADT is a collection of data and operations that work on that data ADT is used to manipulate real-world entities ADT is used to manipulate real-world entities The operations: The operations: describe the data to the rest of the program and describe the data to the rest of the program and allow the rest of the program to change the data allow the rest of the program to change the data

4 Benefits of Using ADTs Hide implementation details Hide implementation details Changes don’t affect the whole program Changes don’t affect the whole program You can make the interface more informative You can make the interface more informative It’s easier to improve performance It’s easier to improve performance The program becomes more self-documenting The program becomes more self-documenting You don’t have to pass data all over your program You don’t have to pass data all over your program You’re able to work with real-world entities rather You’re able to work with real-world entities rather

5 Examples of ADTs and likely operations Blender Blender Turn on Turn on Turn off Turn off Set speed Set speed Cruise Control Cruise Control Set speed Set speed Get current settings Get current settings Resume former speed Resume former speed Deactivate Deactivate

6 Examples of ADTs and likely operations Fuel Tank Fuel Tank Fill tank Fill tank Drain tank Drain tank Get tank capacity Get tank capacity Get tank status Get tank status Menu Menu Start new menu Start new menu Delete menu Delete menu Add menu item Add menu item Remove menu item Remove menu item Activate menu item Activate menu item Display menu Display menu Hide menu Hide menu Get menu choice Get menu choice

7 Examples of ADTs and likely operations Stack Stack Initialize stack Initialize stack Push item onto stack Push item onto stack Pop item from stack Pop item from stack Read top of stack Read top of stack File File Open file Open file Read file Read file Write file Write file Close file Close file Set current file location Set current file location

8 Examples of ADTs and likely operations Elevator Elevator Move up one floor Move up one floor Move down one floor Move down one floor Move to specific floor Move to specific floor Report current floor Report current floor Return to home floor Return to home floor Light Light Turn on Turn on Turn off Turn off

9 List List Initialize Initialize Insert Insert Remove Remove Read Read

10 ADT Guides Treat common objects such as files as ADTs Treat common objects such as files as ADTs Treat even simple items as ADTs Treat even simple items as ADTs Refer to an ADT independently of the medium it’s stored on Refer to an ADT independently of the medium it’s stored on

11 Good Class Interfaces To create a high quality class we must create a good interface To create a high quality class we must create a good interface Class interface is collection of public routines that could be seen and used by other programs or classes Class interface is collection of public routines that could be seen and used by other programs or classes

12

13 This class might have additional routines and data to support these services, but users of the class don’t need to know anything about them This class might have additional routines and data to support these services, but users of the class don’t need to know anything about them The following example shows bad class interface The following example shows bad class interface

14 It’s hard to see any connection among the command stack and report routines or the global data.

15 It could be revised to present a consistent abstraction as illustrated in the following example some of these routines were moved to other, more appropriate classes and some were converted to private routines used by InitializeProgram() and ShutDownProgram().

16 More Class Interface guidelines Provide services in pairs with their opposites If you have an operation that turns a light on, you’ll probably need one to turn it off. If you have an operation to add an item to a list, you’ll probably need one to delete an item from the list. Provide services in pairs with their opposites If you have an operation that turns a light on, you’ll probably need one to turn it off. If you have an operation to add an item to a list, you’ll probably need one to delete an item from the list. Move unrelated information to another class if you found that half a class’s routines work with half the class’s data, and half the routines work with the other half of the data.. Break them up! Move unrelated information to another class if you found that half a class’s routines work with half the class’s data, and half the routines work with the other half of the data.. Break them up!

17 Design and Implementation Issues

18 Containment (“has a” relationships) Containment is the simple idea that a class contains Containment is the simple idea that a class contains One way of thinking of containment is as a “has a” relationship One way of thinking of containment is as a “has a” relationship an employee “has a” name, “has a” phone number, and “has a” tax ID. Therefore.. name, phone number, or tax ID member data (attributes) of the Employee class an employee “has a” name, “has a” phone number, and “has a” tax ID. Therefore.. name, phone number, or tax ID member data (attributes) of the Employee class

19 Containment (“has a” relationships)..... Number of data elements: Number of data elements: “7±2” is a number of items a person can remember while performing other tasks. “7±2” is a number of items a person can remember while performing other tasks. If a class contains more than about seven data members, the class should be decomposed into multiple smaller classes. If a class contains more than about seven data members, the class should be decomposed into multiple smaller classes.

20 Inheritance (“is a” relationships) Applied when one class is a specialization of another class Applied when one class is a specialization of another class Aims to create simpler code by defining a base class that specifies common elements of two or more derived classes Aims to create simpler code by defining a base class that specifies common elements of two or more derived classes The common elements can be routine interfaces, implementations, data members, or data types The common elements can be routine interfaces, implementations, data members, or data types

21 Inheritance (“is a” relationships) … the new class “is a” more specialized version of the older class the new class “is a” more specialized version of the older class Inheritance adds complexity to a program, therefore, it is a dangerous technique Inheritance adds complexity to a program, therefore, it is a dangerous technique Examples: in UOB; Instructor is an employee.. So instructor class is derived from employee class. Examples: in UOB; Instructor is an employee.. So instructor class is derived from employee class.

22 Member Functions and Data Guidelines Keep the number of routines in a class as small as possible Keep the number of routines in a class as small as possible Minimize direct and indirect routine calls to other classes Minimize direct and indirect routine calls to other classes

23 Summary of Reasons to Create a Class Model real-world objects Model real-world objects Reduce complexity Reduce complexity Isolate complexity Isolate complexity Hide implementation details Hide implementation details Limit effects of changes Limit effects of changes

24 Summary of Reasons to Create a Class… Hide global data Hide global data Streamline parameter passing Streamline parameter passing Make central points of control Make central points of control Facilitate reusable code Facilitate reusable code Package related operations Package related operations