Object-Oriented Programming in C++ Grzegorz Jabłoński Department of Microelectronics and Computer Science (K-25) Building B18 (next to the library)

Slides:



Advertisements
Similar presentations
Lecture 6: Software Design (Part I)
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
1 OBJECT-ORIENTED CONCEPTS. 2 What is an object?  An object is a software entity that mirrors the real world in some way.  A software object in OOP.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Introduction To System Analysis and Design
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Department of Computer Science University of Maryland, College Park
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Introduction To System Analysis and design
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.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
Introduction To System Analysis and Design
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Design engineering Vilnius The goal of design engineering is to produce a model that exhibits: firmness – a program should not have bugs that inhibit.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
Systems Analysis and Design in a Changing World, 3rd Edition
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Lecture 6: Structural Modeling
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.
1 What is OO Design? OO Design is a process of invention, where developers create the abstractions necessary to meet the system’s requirements OO Design.
Information System Design (IT60105) Lecture 26 Object-Oriented System Testing.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Learners Support Publications Object Oriented Programming.
CS 3050 Object-Oriented Analysis and Design. Objectives What is “Object-Oriented?” Object-Oriented Approach Vs. Structured Approach How Has the Object-Oriented.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Identifying Classes OO Software Design and Construction Computer Science Dept Va Tech January 2002 ©2002 McQuain WD & Keller BJ 1 Getting Started In the.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Internet and Intranet Protocols and Applications Lecture 5a: HTTP Client-Server Design and Implementation February 15, 2005 Arthur Goldberg Computer Science.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
MANAGING COMPLEXITY Lecture OO01 Introduction to Object-oriented Analysis and Design Abstract Data Types.
CSCE 240 – Intro to Software Engineering Lecture 3.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Object Oriented Systems Design
7. Modular and structured design
CompSci 280 S Introduction to Software Development
Object Oriented Programming
Cmpe 589 Spring 2006.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Object-Oriented Analysis and Design
Chapter 11 Object-Oriented Design
Review: Two Programming Paradigms
11.1 The Concept of Abstraction
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Chapter 10 Thinking in Objects
The Object-Oriented Thought Process Chapter 05
Chapter 20 Object-Oriented Analysis and Design
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Algorithms and Problem Solving
COP 3330 Object-oriented Programming in C++
Introduction to Object-Oriented Programming
Chapter 22 Object-Oriented Systems Analysis and Design and UML
Object-Oriented PHP (1)
CS 2704 Object Oriented Software Design and Construction
Software Engineering Basics
Agenda Software development (SD) & Software development methodologies (SDM) Orthogonal views of the software OOSD Methodology Why an Object Orientation?
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Object-Oriented Programming in C++ Grzegorz Jabłoński Department of Microelectronics and Computer Science (K-25) Building B18 (next to the library)

Syllabus General overview of C++ Classes Fields and methods Operator overload Inheritance Virtual functions Templates Exceptions Class hierarchies C++ standard library (STL)

Lecture Material Goals for design Design paradigms Object-oriented design process Object-oriented design basics Abstraction Interfaces Responsibilities Collaborators Example Identifying objects Identifying relationships

4 Software Engineering Goals for Design Reusability Develop components that can be reused in many systems portable and independent "plug-and-play" programming (libraries) Extensibility Support for external plug-ins (e.g., Photoshop) Flexibility Design so that change will be easy when data/features are added Design so that modifications are less likely to break the system Localize effect of changes

5 Design Process Goal: Create a system In general, the design process is: Divide/Describe system in terms of components Divide/Describe components in terms of sub-components Concept of abstraction Essential for process, hides details of components that are irrelevant to the current design phase Component identification is top-down Decompose system into successively smaller, less complex components Integration is bottom-up Build target system by combining small components in useful ways Design is applied using a paradigm: procedural, modular, object-oriented

6 Abstraction A named collection of attributes and behavior relevant to modeling a given entity for some particular purpose Desirable Properties: Well namedname conveys aspects of the abstraction Coherentmakes sense Accuratecontains only attributes modeled entity contains Minimalcontains only attributes needed for the purpose Completecontains all attribute/behavior needed for the purpose

7 Forms of Abstraction Functions (procedural design) Define set of functions to accomplish task Pass information from function to function Results in a hierarchichal organization of functions Modules (modular design) Define modules, where each has data and procedures Each module has a public and a private section A module groups related data and/or procedures Works as a scoping mechanism Classes/Objects (object-oriented design) Abstract Data Types Divide project in set of cooperating classes Each class has a very specific functionality Classes can be used to create multiple instances of objects

8 Procedural Paradigm Apply procedural decomposition divide the problem into a sequence of simpler sub-problems to be solved independently The resulting program will consist of a sequence of procedure calls The designer thinks in terms of tasks and sub-tasks, identifying what must be done to whom Traditional procedural languages: COBOL, FORTRAN, Pascal, C Design notations: structure charts, dataflow diagrams

9 Problems in Procedural Development The result is a large program consisting of many small procedures There is no natural hierarchy organizing those procedures It is often not clear which procedure does what to what data Control of which procedures potentially have access to what data is poor These combine to make it difficult to fix bugs, modify and maintain the system The natural interdependence of procedures due to data passing (or the use of global data, which is worse) makes it difficult to reuse most procedures in other systems High dependence between functions (high coupling)

10 Procedural Design Consider a domain that deals with geometry (shapes, angles, addition of points, etc.) A procedural design would have: Notice that the central aspect of the design is the procedure, and not the data As a matter of fact, there is no data representation void distance(int x1, int y2, int x2, int y2, float& distance); void angle2radian(float degree, float& radian); void radian2angle(float radian, float& degree); void circlearea(int centerx, int centery, int radius, float& area); void squarearea(int x1, int x2, int width, int height, float &area); void squareperimeter(int x1, int x2, int width, int height, float &prm);...

11 Modular Programming This is a relatively simple extension of the purely procedural approach Data and related procedures are collected in some construct, call it a module The module provides some support for hiding its contents In particular, data can only be modified by procedures in the same module The design process now emphasizes data over procedures. First identify the data elements that will be necessary and then wrap them in modules Typical languages: Ada 83, Modula

12 Problems with Modular Programming Modules do solve most of the (noted) difficulties with procedural programming Modules allow only partial information hiding (when compared with OOP) Cannot have multiple copies of a module, thus restricting your design solutions

13 For the same domain as before, a modular design would have: Notice that the central aspect of the design is still procedure, but there is some data representation Also note that the concept of “Point” is not introduced because it is not needed for the design and it does not provide any advantage to have it Modular Design // Geometry Module struct Circle { int centerx, centery; int radius; }; struct Square { int x1, x2, width, height; }; Circle *NewCircle(int center, int radius); Square *NewSquare(int x1, int x2, int width, int height); float CircleArea(Circle& c); float SquareArea(Square& s); float SquarePerimeter(Square& s); void distance(int x1, int y2, int x2, int y2, float& distance); void angle2radian(float degree, float& radian); void radian2angle(float radian, float& degree);...

14 Object-Oriented Paradigm Think of building the system from parts, similar to constructing a machine Each part is an object which has its own attributes and capabilities and interacts with other parts to solve the problem Identify classes of objects that can be reused Think in terms of objects and their interactions At a high level, think of an object as a thing-in-its- own-right, not of the internal structure needed to make the object work Typical languages: Smalltalk, C++, Java, Eiffel

15 Why Object-Oriented? First of all, OO is just another paradigm... (and there will be more) Any system that can be designed and implemented using OO can also be designed and implemented in a purely procedural manner. But, OO makes some things easier During high-level design, it is often more natural to think of the problem to be solved in terms of a collection of interacting things (objects) rather than in terms of data and procedures OO often makes it easier to understand and forcibly control data access Objects promote reusability

16 OO Design For the same domain as before, an OO design would have: Notice that the central aspect of the design is now the data, the operations are defined together with the data class Point {... float distance(Point &pt); }; class Shape { float Area(); float Perimeter(); Point center(); } class Circle : Shape { private: Point center; int radius; public: // constructors, assignment operators, etc... float Area(); // calc my area float Perimeter(); }; class Square : Shape { private: Point anchor; int width, height; public: // constructors, assignment operators, etc... float Area(); float Perimeter(); };...

17 Design Strategies in OO Development Abstraction modeling essential properties Separation treat what and how independently Composition building complex structures from simpler ones Generalization identifying common elements abstraction separation composition generalization objects classes inheritance templates design patterns reusability extensibility flexibility Design Strategies Software Structures Software Engineering Goals

18 Mapping Abstraction to Software entity attribute s behavior real-world abstractio n software {data, data,…} {method, method,…}

19 Mapping Abstraction to Software in OO entity attribute s behavior real-world abstractio n OO software {data, data,…} {method, method,…}

20 Separation of Interface from Implementation In programming, the independent specification of an interface and one or more implementations of that interface What is to be done vs. How it is to be done Another advantage of this is that we can program depending on the interface without worrying about the implementation Contract-based programming Allows abstraction in the design process Interfac e Implementation visible hidden

21 General Structure of a Class Class a named software representation for an abstraction that separates the implementation of the representation from the interface of the representation A class models an abstraction, which models an entity (possibly “real”) A class represents all members of a group of objects (“instances” of the class) A class provides a public interface and a private implementation The hiding of the data and “algorithm” from the user is important. Access restrictions prevent idle, erroneous, or malicious alterations public private {data, data, ….} {method,method, …} typical organizatio n

22 Object-Oriented Design Process Steps to be carried out to design in OO terms Restricting the domain: Use Cases (Scenarios, Descriptions of use) Identify objects (entities from the domain, data) Identify responsibilities (actions, behavior) How to define behavior Identify collaborations Decide whether behavior is accomplised by a single class or through the collaboration of a number of "related" classes Static behavior Behavior always exists Dynamic behavior Depending of when/how a behavior is invoked, it might or might not be legal Identify relationships between objects Composition by association, aggregation, links, others

23 Getting Started In the beginning… there is a specification: The specification is usually somewhat unsatisfactory Frequently important details are missing Often, much is said in the specification that is unimportant Specification: Design a music catalog system. The system must support adding recordings, storing information about artist, album title, song title, song composer, etc. The user of the system should be able to search the collection for any information. It should also allow the user to browse the collection.

24 Identifying the Objects We must: Identify potential objects from the specification Eliminate phony candidates Determine how the legitimate objects will interact Extrapolate classes from the objects This process: Requires experience to do really well Requires guidelines, none of which are entirely adequate Often uses several approaches together Should lead to too many rather than too few potential objects

25 Several Approaches Abbott and Booch suggest: use nouns, pronouns, noun phrases to identify objects and classes singular -> object, plural -> class not all nouns are really going to relate to objects Coad and Yourdon suggest: identify individual or group "things" in the system/problem Ross suggests common object categories: people places things organizations concepts events

26 Objects and the Problem Domain What constitutes a "potential object" depends on the problem domain Discuss with a domain expert — a person who works in the domain in which the system will be used Try to identify objects from the way that the users/experts think about the system/problem Specification: Design a music catalog system. The system must support adding recordings, storing information about artist, album title, song title, song composer, etc. The user of the system should be able to search the collection for any information. It should also allow the user to browse the collection.

27 Eliminate "false" Objects An object should: be a real-world entity be important to the discussion of the requirements have a crisply defined boundary make sense; i.e., the attributes and behaviors should all be closely related Danger signs: class name is a verb class is described as performing something class involves multiple abstractions class is derived from another, but has few features itself class has only one public method class has no methods

28 Example: Music System Looking for nouns First cut: music catalog (collection) system user song title artist recordings (album) composer information Specification: Design a music catalog system. The system must support adding recordings, storing information about artist, album title, song title, song composer, etc. The user of the system should be able to search the collection for any information. It should also allow the user to browse the collection. Which of these are important to consider in our design? Real-world entity, important for problem, clearly definable?

29 Example: Music System Reject (for now) music (refers to the type of information stored, but nothing musical stored) catalog (collection, system) - all the same information - general name to refer to pieces of the collection user - external to the system, plays a role in the system song, title, artist, composer recordings (album) Data structure support required... (organization of elements in domain) Catalog has a collection of recordings Recording has title, artist name, list of songs Song has title, composer name, artist name Do we need to consider “title” a class? How about a person’s name?

30 Example: Music System What about overall control? The primary controller may be either procedural or an object Collection User uses Catalog, which contains the collection, a list of Recording objects (somehow) provides support for each of the required actions However, the Collection should respond to instructions (events), not seek them out. In the implementation, we must parse an input script, or have a GUI. Either way, that's not part of the Collection, although it would interact with it

31 General Structure of an Object Object: a distinct instance of a given class that encapsulates its implementation details and is structurally identical to all other instances of that class An object “encapsulates” its data and the operations that may be performed on that data An object’s private data may only be accessed via the member functions defined within the object’s class An object hides details of representation and implementation from the user code data metho d interfac e implementatio n