CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2005.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CPS 108 : Spring What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking.
Programming Languages and Paradigms Object-Oriented Programming.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Elements of OO Abstraction Encapsulation Modularity Hierarchy: Inheritance & Aggregation 4 major/essential elements3 minor/helpful elements Typing Concurrency.
Introducing Allors Applications, Tools & Platform.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Object-Oriented Programming Chapter Chapter
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Overview of C++ Polymorphism
Appendix 1 - Packages Jim Fawcett copyright (c)
Chapter 2 Objects and Classes
Motivation for Generic Programming in C++
Examples (D. Schmidt et al)
CSE691 Software Models and Analysis.
Jim Fawcett CSE687-OnLine – Object Oriented Design Summer 2017
Copyright © Jim Fawcett Spring 2017
Data Abstraction: The Walls
Jim Fawcett CSE775 – Distributed Objects Spring 2017
Jim Fawcett CSE687 – Object Oriented Design Spring 2001
Abstract Factory Pattern
Jim Fawcett CSE687 – Object Oriented Design Spring 2016
Jim Fawcett CSE775 – Distributed Objects Spring 2009
CSE687 – Object Oriented Design
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Abstract Data Types and Encapsulation Concepts
Object-Oriented Programming (OOP) Lecture No. 45
Exceptions, Templates, and the Standard Template Library (STL)
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Jim Fawcett CSE687 – Object Oriented Design Spring 2005
Copyright © by Curt Hill
C++, OBJECT ORIENTED PROGRAMMING
11.1 The Concept of Abstraction
Satisfying Open/Closed Principle
Jim Fawcett CSE687-OnLine – Object Oriented Design Summer 2017
Object-Orientated Programming
object oriented Principles of software design
Abstract Factory Pattern
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Intent (Thanks to Jim Fawcett for the slides)
Chapter 2 Objects and Classes
Object Oriented Practices
Abstract Data Types and Encapsulation Concepts
Abstract Data Types and Encapsulation Concepts
Exceptions 2 CMSC 202.
More Object-Oriented Programming
Parameter Passing Actual vs formal parameters
Chapter 11: Inheritance and Composition
Overview of C++ Polymorphism
Principles of Object-Oriented Design
Jim Fawcett CSE687 – Object Oriented Design Spring 2003
Chapter 8 - Design Strategies
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Programming to Interfaces
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2006
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
11.1 The Concept of Abstraction
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Introduction to Classes and Objects
Presentation transcript:

CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2005

Survey Major features of the Standard C++ Language Classes Constructors and destructors Operator model Class relationships References Exceptions Templates Major features of the Standard C++ Library Streams STL – containers, iterators, algorithms Survey of C++ Language

C++ Classes Three design prime directives are: C++ Class Model Make designs cohesive Use strong encapsulation Minimize coupling C++ Class Model C++ evolved initially by adding classes to the C language. Classes provide direct support for the last two directives: Support public, protected, and private access control Eliminate the need for global data Provide const qualifiers used to qualify member functions and their arguments. C++ classes support a deep copy object model. Assignment and Copy construction are value-based operations. If you define a destructor you almost always need to define copy construction and assignment operations, or make them private. Member functions are the exclusive mechanism for transforming and accessing class data. Defining a class: SurvivalGuide.doc#classes Survey of C++ Language

Features Constructors and destructors Operator model: Objects are created from a class pattern only by calling a constructor. Whenever the thread of execution leaves a scope, all objects created in that scope are destroyed, even in the presense of exceptions. Part of that destruction is the execution of the objects’ destructors. The C++ ctor/dtor model is intended to be the universal mechanism for managing allocated resources. Exceptions make this essential. Operator model: Helps to move source code closer to the application domain. x@y  x.X::operator@(y) member operator x@y  ::operator@(x,y) global operator Class relationships Inheritance, composition, aggregation, and using Support a rich model for managing run-time behavior of programs. On demand construction Lazy evaluation References X& rx = x an alias Exceptions throw, try, catch don’t have to constantly check for rare events Survey of C++ Language

Survey of C++ Language

VTbls Survey of C++ Language

Features Templates Generic functions and classes: Policies: Defer specifying one or more library types until design of an application Policies: Configure classes with specific behaviors at application design time SmartPtr  ownership, checking, memory allocation, threading Template Metaprogramming Compile time computations on types Functors use Typelist to support variable argument type sequences Partial Template Specialization Detailed control of class’s type definitions Template Template parameters Template arguments may be generic types, integral types, function pointers, and other templates Survey of C++ Language

Streams Simple structure: Stream classes: std::ios supports formatting and error reporting. streambuf manages the transfer of character strings to and from devices. iostream provides a user interface and conversion of base types to and from strings of characters. Stream classes: iostream: console input and output iofstream: input and output to files iostringstream: input and output to strings in memory Survey of C++ Language

Standard Template Library Generic containers: vector<T> dequeue<T> list<T> set<T>, multiset<T> map<U,V>, multimap<U,V> iterators: forward, reverse, constant, bidirectional, random access algorithms many solution-side operations that take iterators and functors to provide a simple connection to the STL containers work with simple arrays as well Survey of C++ Language

Bad Designs What makes a design bad? Robert Martin suggests[1]: Rigidity It is hard to change because every change affects too many other parts of the system. Fragility When you make a change, unexpected parts of the system break. Immobility It is hard to reuse a part of the existing software in another application because it cannot be disentangled from the current application. The design principles discussed in class are all aimed at preventing “bad” design. Survey of C++ Language

Principles Liskov Substitution Principle Open/Closed Principle A pointer or reference to a base class may be replaced by a pointer or reference to a derived class without making any changes to its clients. Supports the powerful hook idea – allow applications to specify what a specific library’s function call means. Open/Closed Principle Components should be open for extension but closed for modification. Dynamic binding and templates are excellent means to accomplish this. Dependency Inversion Principle Policies and their Implementations should depend on shared abstractions, not on each other’s concrete details. Programming to interfaces and using object factories are what’s needed. Interface Segregation Principle A using class should not have to bind to parts of an interface it doesn’t need. Careful partitioning of classes, mixins, and multiple interfaces per class help support this principle. Survey of C++ Language

Next Standardization Process underway for several years Will probably finish in 2009 Focus mostly on library Survey of C++ Language

In Balance Pros Very flexible construction of program structure and syntax. Deep control of memory and execution Rich memory model Scope-based resource management Powerful access to objects and functions through pointers Very flexible management of binding using virtual functions and templates Can write very efficient code Easier to manage data than C Better control of memory than Fortran, C#, and Java Many examples of excellent code STL library Boost library Loki library Cons Complex language Need help to understand all the features ref #1, Stroustrup Need help to use effectively Ref #2, Sutter & Alexandrescu Ref #3, Dewhurst Need help to avoid traps & pitfalls Ref #4, Sutter Ref #5, Dewhurst Can write very inefficient code Copying into and out of stack frames Copying into heap Clients hold type information of their servers Makes change much more labor intensive Need interfaces and object factories to avoid this extra labor Survey of C++ Language

References Understand language details Use language effectively C++ Programming Lanaguage, Bjarne Stroustrup, Addison-Wesley, 1997 Use language effectively C++ Coding Standards, Herb Sutter and Andrei Alexandrescu, Addison-Wesley, 2005 C++ Common Knowledge, Stephen Dewhurst, Addison-Wesley, 2005 Effective STL, Scott Meyers, Addison-Wesley, 2001 Avoid Traps and Pitfalls Exceptional C++ Style, Herb Sutter, Addison-Wesley, 2005 C++ Gotchas, Stephen Dewhurst, Addison-Wesley, 2003 Compare with C# - understand, use effectively, avoid pitfalls Effective C#, Bill Wagner, Addison-Wesley, 2005 Survey of C++ Language

Additional References Speaking C++ as a Native, Bjarne Stroustrup http://conferences.fnal.gov/acat2000/program/plenary/STROUSTRUP.pdf Wrapping C++ Member Function Calls, Bjarne Stroustrup, C++ User’s Report, June 2000 http://www.research.att.com/~bs/wrapper.pdf Same idea used in lockingPtr. Provides a before and after call interception for service code. Stroustrup’s home page: http://www.research.att.com/~bs/homepage.html Scott Meyer’s Publications: http://www.aristeia.com/publications_frames.html Herb Sutter’s Publications: http://www.gotw.ca/publications/index.htm Andre Alexandrescu’s Publications: www.moderncppdesign.com/publications/main Survey of C++ Language

End of Presentation