Chapter 6. Object- Oriented Programming Part II

Size: px
Start display at page:

Download "Chapter 6. Object- Oriented Programming Part II"

Transcription

1 Chapter 6 Object- Oriented Programming Part II

2 6: Preview issues surrounding the object creational process the Abstract Factory design pattern private and protected inheritance multiple inheritance comparison of delegation and inheritance programming to an interface several new design patterns: - Prototype - Bridge - Adapter - State

3 6: Managing the Creational Process, Part II: Abstract Factory Design Pattern the Instantiating Operation Idiom specified how to design classes so that you can take control over the creation of their objects the Singleton design pattern was designed so that at most one instance of a class may be created the Abstract Factory design pattern is used to manage the general creational process in the context of classes and inheritance

4 6: Managing the Creational Process, Part II (cont.) When a class constructor is used to create an object, it creates several dependencies: it makes your code dependent on the objects of this particular class, it makes it dependent on the name of the specific class used to create it (the class name is said to be hard-coded). Is there anything wrong with hard coding class names? It makes it difficult to modify your program, should you want to replace some class in the program with a different class, say because the new class has a better implementation, but has the same behavior.

5 6: Managing the Creational Process, Part II (cont.) Consider a polynomial or a rational function represented by a string. In order to operate on the function, for example to display it: you need to read in the string after the string is read, you have to parse it to decide on the type of function it represents use it to create an object of type Polynomial or an object of type Rational then use its interface to perform the display operation. If you are hard coding the class used to create new objects in your program, then whenever new function types are added, each part of the code that creates objects representing these functions has to be modified.

6 6: Managing the Creational Process, Part II (cont.) Solution: encapsulate the creation of objects in another class use the interface of this class to get new objects whenever they are required. Any future changes to the creational process will be isolated to the class that produces objects. Terminology: the object being created is a product the object that creates other objects is a factory; responsible for producing a specific product using a factory method.

7 6: Managing the Creational Process, Part II (cont.) In our case of mathematical functions we have two products: a polynomial function a rational function Your code would use two classes: an abstract product class, i.e. the base class for all products, the factory class; the factory method has a string parameter to decide which product it should produce.

8 6: Managing the Creational Process, Part II (cont.) Actions: create a factory object use its factory method to create a specific product use the abstract product interface to invoke the required operation for a product; for example, to display the rational function. The product dependency is now encapsulated in the factory class, which means that the remainder of your code is not dependent on a specific product.

9 6: Managing the Creational Process, Part II (cont.) To construct an object, you need to know the type of this object: the constructor cannot be virtual it cannot be abstract, which would allow the derived class to decide what type of object is created. A factory method is virtual: AbstractProduct* Factory::factoryMethod(...); returns a product derived from the class AbstractProduct. Also known as a virtual constructor: various classes derived from Factory, such as AnotherFactory can decide on the specific type of a product to create.

10 6: Managing the Creational Process, Part II (cont.) The factory method is often useful in combination with the Template Method pattern. If the template method needs to create an object, then it can use a factory method rather than hard coding class names. Consider an abstract class Factory, which has a factory method to create products. These products are derived from an abstract class Product. Concrete factories (classes derived from Factory) create concrete products. A template method templateop() uses the factory method to return objects of classes derived from the class Product

11 6: Managing the Creational Process, Part II (cont.) The client who wants to invoke the template method: creates a concrete factory calls the template method; this method will use a factory method to create a product, and then use this product.

12 6: Abstract Factory The Abstract Factory: an abstract class with a method to return specific factories. Also has abstract factory methods to return instances of concrete derived classes of the abstract product. The user of this never creates objects directly; instead, gets a factory and asks this factory to create a concrete product.

13 6: Abstract Factory (Example) A system where various kinds of objects are created: from interactive file input on a local machine from a remote machine on the network. The user should be able to code to the same interface: An abstract product class with two abstract functions to open a file for reading and writing Two concrete product classes derived from this abstract class that implement a local and a remote file access a concrete factory has createabstractproduct(string fname) to examine fname and depending on whether it represents a local filename or a remote filename, to return the appropriate concrete product.

14 6: Abstract Factory (Example) Various simple file operations, such as computing the number of lines in a file can be implemented: without caching with caching We need to create two different products (instances that either do or do not cache). The responsibility of creating products will be assigned to an abstract factory method; the derived class will implement this abstract method as a function returning an instance of this class. The function lines() is a template method that uses the factory method to create the product (which is a cached or a non-cached application), and then invokes the operation lines() from this product.

15 6: Abstract Factory (Example)

16 Abstract Factory class AbstractFileOps { //abstract product public: virtual long lines() const = 0; protected: }; virtual ~AbstractFileOps();

17 class FileOps : public AbstractFileOps { // implements public: virtual long lines() const; FileOps(const string&); ~FileOps(); private: mutable ifstream filevar_; }; Abstract Factory // concrete // product class CachedFileOps : public AbstractFileOps { public: virtual long lines() const; virtual void clearcache(); CachedFileOps(const string&); ~CachedFileOps(); private: mutable long lines_; mutable bool linescached_; mutable ifstream filevar_; };

18 class AbstractApplication Abstract { // Factory abstract factory public: }; virtual AbstractFileOps* factorymethod() const = 0; long lines() const; virtual ~AbstractApplication(); // template method long AbstractApplication::lines() const { AbstractFileOps* afo = factorymethod(); return afo->lines(); } AbstractApplication::~AbstractApplication() {}

19 class RegularApplication : public AbstractApplication { public: Abstract Factory // concrete factory implements RegularApplication(const string&); ~RegularApplication(); virtual FileOps* factorymethod() const; private: string filename_; }; class CachedApplication : public AbstractApplication { public: CachedApplication(const string&); ~CachedApplication(); virtual CachedFileOps* factorymethod() const; void clearcache(); private: string filename_; };

20 FileOps* RegularApplication::factoryMethod() const { return new FileOps(filename_); Abstract Factory } RegularApplication::RegularApplication(const string& filename) : filename_(filename) {} CachedFileOps* CachedApplication::factoryMethod() const { return new CachedFileOps(filename_); // same kind of constructor for CachedApplication void CachedApplication::clearCache() { CachedFileOps* cs = factorymethod(); cs->clearcache(); }

21 int main(int argc, char* argv[]) { if(argc!= 3) { Abstract Factory cerr << "usage " << argv[0] << " file1 file2" << endl; } return 1; AbstractApplication* aa= new CachedApplication(argv[1]); AbstractApplication* bb= new RegularApplication(argv[2]); cout<<"lines in "<<argv[1] << " " << aa->lines() << endl; cout << "clear cache" << endl; aa->clearcache(); cout<<"lines in "<<argv[1] << " " << aa->lines() << endl; cout<<"lines in "<<argv[2] << " " << bb->lines() << endl; }

22 6: Abstract Factory (Example)

23 class FunctionFactory { // abstract public: Abstract Factory virtual Function* createfunction(const string&) const=0; static FunctionFactory* getfactory(const string&); }; FunctionFactory* FunctionFactory::getFactory( const string& s) { string::size_type pos = s.find_first_of('/'); // if s represents a polynomial if(pos == string::npos) return new PolynomialFactory(); return new RationalFactory(); }

24 class PolynomialFactory : public FunctionFactory { public: Abstract Factory virtual Polynomial* createfunction(const string&) const; }; class RationalFactory : public FunctionFactory { public: virtual Rational* createfunction(const string&) const; virtual ~RationalFactory(); }; Rational* RationalFactory::createFunction( const string& s) const { return new Rational(s); }

25 6: Abstract Factory (Example) An application in which you use two kinds of functions: polynomials and rational functions (quotients of two polynomials). The client of the program uses an abstract factory, FunctionFactory and an abstract product, Function. There are two concrete factories, RationalFactory and PolynomialFactory to create the concrete products Rational and Polynomial: string s; cin >> s; FunctionFactory* factory = FunctionFactory::getFactory(s); Function* foo = factory->createfunction(s); foo->display();

26 6: Private Inheritance Public inheritance: all public features of the base class are inherited allows us to substitute properly implemented objects of derived classes for objects of the base class. Private inheritance: don t inherit the entire interface don t inherit even a part of the entire interface inherit just the implementation of the various operations. For example, you may need to operate on data with more stringent requirements, and so may need to restrict the original interface

27 6: Private Inheritance (cont.) class Dequeue { public: Dequeue(int size = 10); virtual ~Dequeue(); void insertl(int); void insertr(int); int removel(); int remover(); protected: int size_; int* elem_; int left_; int right_; };

28 6: Private Inheritance (cont.) class Queue: private Dequeue { public: using Dequeue::insertL; using Dequeue::removeR; Queue(int size = 10); virtual ~Queue(); }; equivalent to: class Queue { //PSEUDO-CODE public: void insertl(int); int remover(); Queue(int size = 10); virtual ~Queue(); private: // note: private // restore insertl(); // restore remover();

29 6: Private Inheritance (cont.) class Stack : private Dequeue { // doesn't inherit the interface public: Stack(int size = 10); ~Stack(); void push(int); int pop(); bool full() const; }; void Stack::push(int i) { insertl(i); } bool Stack::full() const { return left_ == right_; }

30 6: Private Inheritance (cont.) Since the interface is not inherited, private inheritance does not support isa relationships: a Queue is not a Stack Queue objects cannot be used where Stack objects are expected. Private inheritance represents a is-implemented-in-terms-of relationship: Stack is-implemented-in-terms-of Dequeue. In other words, private inheritance allows the derived class to reuse the code of the base class.

31 6: Protected Inheritance Protected inheritance: all public features of the base class become protected features of the derived class (protected features of the base class continue to be protected in the derived class) useful if you do not want to finalize the derivations, that is you want to make it possible to have additional derived classes: class Stack : protected Dequeue { public: Stack(int size = 10); ~Stack(); void push(int); int pop(); bool full() const; };

32 6: Revisiting Inheritance A default implementation of a virtual function may turn out to be dangerous, because the designer of the derived class may forget to add her or his own implementation: class Shape { public: virtual void draw() const;... }; void Shape::draw() {... // default implementation; draws a logo shape } class Rectangle : public Shape { public:... // no draw() here };

33 6: Revisiting Inheritance Shape* s = new Rectangle; s->draw(); // draws the logo, not the rectangle You can force the inheriting clients to provide their own implementations, and have a default implementation in the base class: class Shape { // abstract } public: virtual void draw() const = 0;... }; void Shape::draw() { // default implementation; draws a logo shape...

34 6: Revisiting Inheritance class Rectangle : public Shape { // still abstract public:... // no implementation of draw() }; Shape* s = new Rectangle; s->draw(); // Rectangle is abstract The base class default implementation of draw() can be used to implement the derived implementation: void Rectangle::draw() { Shape::draw(); // default implementation... // specific for Rectangle }

35 Default Implementation To provide a default implementation that must be redefined in a derived class, use pure virtual operations and provide their implementation.

36 6: Inheritance versus Delegation white-box reuse through inheritance. Internals of the parent classes are visible to the derived classes. Uses a compile-time relationship between two classes (a base class and a derived class) and you cannot make modifications at run-time. black-box reuse through delegation. Internal details of the objects are not visible. Uses a runtime-time relationship between two objects. white-box black-box

37 6: Inheritance versus Delegation (cont.) -The handle represents an abstraction, and is visible to the client -The invisible body provides the implementation. -Object composition combined with inheritance is often a better alternative than just inheritance: the client programs according to an interface provided by a class (the handle) whose object delegates requests to the object providing the implementation (the body). the client's code only has to be relinked with the modified code decomposes an abstraction into smaller, more manageable parts helps the programmer to define additional functionality for the implementation without affecting the client; e.g. support for the sharing of objects by using reference counting

38 6: Multiple Inheritance, Part I C++ Comments about C++ class CE : public Ifc { class Ifc : public Ifc1, public Ifc2 { class CE : public C { class CE : public C, public Ifc { class CE : private C, public Ifc { public derivation to implement abstract interface public derivation to extend abstract interfaces of several classes public derivation to inherit an interface public derivation to implement abstract interface and derived class public derivation from the interface and private derivation from the class (mixin class).

39 6: Programming to an Interface One of the important goals in writing good code is reusability: minimize the dependencies between subsystems Program to an interface, not an implementation access objects in terms of their abstract interfaces, that is interfaces consisting entirely of abstract operations do not use concrete operations because this requires binding to a specific implementation.

40 6: Decoupling Interfaces and Implementations The Account class is abstract; there may be various derived classes, such as SavingsAccount, which implement Account. The handle class Bank does not need to be changed when new derived classes are used.

41 6: The Bridge design pattern Using inheritance to provide implementations of a single abstraction: tightly binds these implementations to the abstraction makes it difficult to update the client's code, and reuse the abstraction. In C++, the complete class definition, including the private and protected sections, is needed in order to compile the client's code leads to a tight coupling between the abstraction and its implementations makes modifications more difficult. The Bridge Design Pattern a structural pattern separates and decouples the abstraction and the implementation Skip Bridge

42 6: The Bridge design pattern (cont.) There are two independent class hierarchies bridged through a delegate. Implementation details are hidden from the clients, who access only the abstraction. Both the abstraction and the implementation classes can be extended independently.

43 6: Reference Counting You can use the Bridge Design Pattern to share objects and use reference counting to deallocate them when they are no longer used: have the counters in the body have the copying operations in the handle. These copying operations could include dealing with things like object assignments: incrementing the reference counter of the right hand side decrementing the reference counter of the left hand side

44 6: Reference Counting (cont.) class Point { public: Point(double = 0, double = 0); virtual ~Point(); double getx() const; double gety() const; private: double x_; double y_; }; To add reference counters to Point objects, we need to create a new class, here called PointCounted, which is used by the clients. Therefore, this PointCounted class is the handle, while the class Point is the body.

45 6: Reference Counting (cont.) class PointCounted { public: PointCounted(double = 0, double = 0); //creates a point PointCounted(const PointCounted&); PointCounted(const Point&); PointCounted& operator=(const PointCounted&); ~PointCounted(); double getx() const; double gety() const; private: Point* p_; int* count_; };

46 PointCounted::PointCounted(double PointCounted x, double y) { p_ = new Point(x, y); count_ = new int(1); } PointCounted::PointCounted(const Point& pp) { p_ = new Point(pp); count_ = new int(1); } PointCounted::~PointCounted() { --(*count_); if (*count == 0) { delete p_; delete count_; } } // one fewer reference // garbage double PointCounted::getX() const { return p_->getx(); // same for Y }

47 PointCounted::PointCounted(const PointCounted& pc) { PointCounted count_ = pc.count_; } p_ = pc.p_; ++(*count_); PointCounted& PointCounted::operator=(const PointCounted& pc) { if(this == &pc) return *this; ++(*pc.count_); // RHS has one more reference --(*count_); // LHS has one less reference if(*count_ == 0) { // garbage delete p_; delete count_; } count_ = pc.count_; p_ = pc.p_; return *this; }

48 6: Reference Counting (cont.) PointCounted p1(1, 3); if(...) { PointCounted p2(p1); // share the same point cout << p1.getx() << " " << p2.gety() << endl; } // now there is only one copy PointCounted p2(14, 4); p1 = p2; // one copy is collected

49 Avoiding Recompilation To avoid the need for unnecessary recompilation of the client's code, separate the interface and the implementation, and include only those header files that are absolutely necessary.

50 6: Creating and Copying Abstract Interfaces: Prototype Design Pattern The cloning operation has its roots in yet another creational design pattern: the Prototype design pattern gives a flexible alternative to inheritance. The client class creates a prototype object; when this client again needs to create a new object, it asks the prototype object to clone itself. Therefore, objects that are used as prototypes must support the clone() operation, in addition to their own operations Skip Prototype

51 6: Creating and Copying Abstract Interfaces: Prototype Design Pattern (cont.) Application of the Prototype design pattern: the creation and copying of an abstract interface.

52 class Account { // abstract prototype public: Account virtual void open() = 0; virtual void withdraw(double) = 0; virtual void deposit(double) = 0; virtual Account* clone() const = 0; virtual Account* create() const = 0; }; class SavingsAccount : public Account { // implements public: virtual void open(); virtual void withdraw(double); virtual void deposit(double); virtual SavingsAccount* clone() const; virtual SavingsAccount* create() const; protected:... };

53 SavingsAccount* SavingsAccount::clone() const { return new SavingsAccount(*this); }; SavingsAccount* SavingsAccount::create() const { return new SavingsAccount(); }; The variable prot is assumed to point to the prototype account: Account* a = prot->clone(); If the value of the prot is an object of the class SavingsAccount, then clone() returns an object of the same class (polymorphism). How do we create the initial prototype?

54 class BankFactory { public: Account BankFactory(Account*); virtual Account* makeaccount() const; private: Account* accprototype_; }; BankFactory::BankFactory(const Account* a) { accprototype_ = a; } To configure a factory for a particular type of account: BankFactory saving(new SavingsAccount()); The client of BankFactory can use its operation makeaccount() to clone the prototype: Account* BankFactory::makeAccount() const { } return accprototype_->clone();

55 Account Now, let's look at the client code: Account* sa = saving.makeaccount(); Account* sa1 = sa->clone();//clone existing saving account Account* sa2 = sa->create(); // create new saving account

56 6: Creating and Copying Abstract Interfaces: Prototype Design Pattern (cont.) -delegate_:account*

57 6: Modifying Existing Interfaces: Adapter Design Pattern Consider a class, called Adaptee with a given interface, and an application that needs almost exactly this kind of an interface, but with some minor differences. Modifying the class interface is not necessarily a feasible solution; it would really be useful to adapt the existing Adaptee to the needs at hand. The Adapter Design Pattern can help us to accomplish precisely this. The pattern is an example of a structural pattern: how to compose existing objects and classes to form new structures. Skip Adapter

58 6: Modifying Existing Interfaces: Adapter Design Pattern (cont.) Class adapters: use mixins to inherit and implement the interface of TargetIfc and to inherit only the implementation of Adaptee

59 6: Modifying Existing Interfaces: Adapter Design Pattern (cont.) Object adapters: use object composition to delegate requests to Adaptee

60 class DictionaryNamespace::DictionaryIfc { public: Adapter virtual void insert(const string&) = 0; // abstract virtual void remove(const string&) = 0; virtual bool member(const string&) const = 0; }; class OldStuffNamespace::Dictionary { // existing public: void insert(const char* const); void remove(const char* const); bool member(const char* const) const; private:... // not shown here }; In order to implement DictionaryNamespace::DictionaryIfc an adapter mixin class ClassDictionaryAdapter

61 class DictionaryNamespace::ClassDictionaryAdapter : public DictionaryNamespace::DictionaryIfc Adapter // implements private OldStuffNamespace::Dictionary { // inherit impl. public: virtual void insert(const string&); virtual void remove(const string&); virtual bool member(const string&) const; }; void DictionaryNamespace::DictionaryAdapter insert(const string& s) { OldStuffNamespace::Dictionary::insert(s.c_str()); }

62 6: Self-modifying Interfaces: State Design Pattern The State pattern is useful if an object may be in a large number of states, and the behavior of this object changes at run-time whenever its state changes. Rather than coding the behavior using a large switch statement, this behavior is implemented by the subclasses of the state. Skip State

63 6: Self-modifying Interfaces: State Design Pattern (cont.) The client of the State Design Pattern communicates with a class called Context. This design pattern also includes an abstract class called the State; concrete states implement this class s behavior.

64 6: Self-modifying Interfaces: State Design Pattern (cont.) An example of an application of the State design pattern: TCP connections where a TCP object may be in several states, such as: Established Closed Listening. When a TCP connection object receives a request, its response depends on its state. For example, the action taken for an Open request depends on whether the current state is Established or Closed.

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1 CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information

Topics in Object-Oriented Design Patterns

Topics in Object-Oriented Design Patterns Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

6 Architecture of C++ programs

6 Architecture of C++ programs 6 Architecture of C++ programs 1 Preview managing memory and other resources "resource acquisition is initialization" (RAII) using std::auto_ptr and other smart pointers safe construction of an object

More information

Programmazione. Prof. Marco Bertini

Programmazione. Prof. Marco Bertini Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Design patterns Design patterns are bug reports against your programming language. - Peter Norvig What are design

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecturer: Raman Ramsin Lecture 20: GoF Design Patterns Creational 1 Software Patterns Software Patterns support reuse of software architecture and design. Patterns capture the static

More information

Lecture 15a Persistent Memory & Shared Pointers

Lecture 15a Persistent Memory & Shared Pointers Lecture 15a Persistent Memory & Shared Pointers Dec. 5 th, 2017 Jack Applin, Guest Lecturer 2017-12-04 CS253 Fall 2017 Jack Applin & Bruce Draper 1 Announcements PA9 is due today Recitation : extra help

More information

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance?

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance? INHERITANCE - Part 1 OOP Major Capabilities Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors encapsulation

More information

INHERITANCE - Part 1. CSC 330 OO Software Design 1

INHERITANCE - Part 1. CSC 330 OO Software Design 1 INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1

More information

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) Design Pattern CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) A. Design Pattern Design patterns represent the best practices used by experienced

More information

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1 What is a Design Pattern? Each pattern Describes a problem which occurs over and over again in our environment,and then describes the core of the problem Novelists, playwrights and other writers rarely

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns

ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/60 ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns Professor Jia Wang Department of Electrical

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Today we are going to talk about an important aspect of design that is reusability of design. How much our old design

More information

OBJECT ORIENTED PROGRAMMING USING C++

OBJECT ORIENTED PROGRAMMING USING C++ OBJECT ORIENTED PROGRAMMING USING C++ Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded

More information

Ch. 11: References & the Copy-Constructor. - continued -

Ch. 11: References & the Copy-Constructor. - continued - Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011 Design Patterns Lecture 1 Manuel Mastrofini Systems Engineering and Web Services University of Rome Tor Vergata June 2011 Definition A pattern is a reusable solution to a commonly occurring problem within

More information

Chapter 5. Object- Oriented Programming Part I

Chapter 5. Object- Oriented Programming Part I Chapter 5 Object- Oriented Programming Part I 5: Preview basic terminology comparison of the Java and C++ approaches to polymorphic programming techniques introduced before in the context of inheritance:

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester Design Patterns Comp2110 Software Design Department of Computer Science Australian National University Second Semester 2005 1 Design Pattern Space Creational patterns Deal with initializing and configuring

More information

Structure Patters: Bridge and Flyweight. CSCI 3132 Summer

Structure Patters: Bridge and Flyweight. CSCI 3132 Summer Structure Patters: Bridge and Flyweight CSCI 3132 Summer 2011 1 Introducing the Bridge Pa1ern Intent To decouple an abstrac7on from its implementa7on so that the two can vary independently. What does it

More information

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns EPL 603 TOPICS IN SOFTWARE ENGINEERING Lab 6: Design Patterns Links to Design Pattern Material 1 http://www.oodesign.com/ http://www.vincehuston.org/dp/patterns_quiz.html Types of Design Patterns 2 Creational

More information

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8 Object Oriented Methods with UML Introduction to Design Patterns- Lecture 8 Topics(03/05/16) Design Patterns Design Pattern In software engineering, a design pattern is a general repeatable solution to

More information

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D. Software Design Patterns Jonathan I. Maletic, Ph.D. Department of Computer Science Kent State University J. Maletic 1 Background 1 Search for recurring successful designs emergent designs from practice

More information

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently. Gang of Four Software Design Patterns with examples STRUCTURAL 1) Adapter Convert the interface of a class into another interface clients expect. It lets the classes work together that couldn't otherwise

More information

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017 OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

INHERITANCE - Part 1. CSC 330 OO Software Design 1

INHERITANCE - Part 1. CSC 330 OO Software Design 1 INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1

More information

Inheritance Modes. Controlling Inheritance 1

Inheritance Modes. Controlling Inheritance 1 Inheritance Modes Controlling Inheritance 1 When deriving a class D from a base class B, we may specify that access to the base class is any of the following: public, protected, private. The base class

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

An Introduction to Patterns

An Introduction to Patterns An Introduction to Patterns Robert B. France Colorado State University Robert B. France 1 What is a Pattern? - 1 Work on software development patterns stemmed from work on patterns from building architecture

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecture 14: Design Workflow Department of Computer Engineering Sharif University of Technology 1 UP iterations and workflow Workflows Requirements Analysis Phases Inception Elaboration

More information

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I

See the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I Polynomial Class Polynomial(); Polynomial(const string& N, const vector& C); Polynomial operator+(const Polynomial& RHS) const; Polynomial operator-(const Polynomial& RHS) const; Polynomial operator*(const

More information

Design Patterns. (and anti-patterns)

Design Patterns. (and anti-patterns) Design Patterns (and anti-patterns) Design Patterns The Gang of Four defined the most common object-oriented patterns used in software. These are only the named ones Lots more variations exist Design Patterns

More information

8. Object-oriented Programming. June 15, 2010

8. Object-oriented Programming. June 15, 2010 June 15, 2010 Introduction to C/C++, Tobias Weinzierl page 1 of 41 Outline Recapitulation Copy Constructor & Operators Object-oriented Programming Dynamic and Static Polymorphism The Keyword Static The

More information

L4: Inheritance. Inheritance. Chapter 8 and 10 of Budd.

L4: Inheritance. Inheritance. Chapter 8 and 10 of Budd. L4: Inheritance Inheritance Definition Example Other topics: Is A Test, Reasons for Inheritance, C++ vs. Java, Subclasses and Subtypes 7 Forms of Inheritance Discussions Chapter 8 and 10 of Budd. SFDV4001

More information

Programming C++ Lecture 5. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor

Programming C++ Lecture 5. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Programming C++ Lecture 5 Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Templates S Function and class templates you specify with a single code segment an entire

More information

C++ Constructor Insanity

C++ Constructor Insanity C++ Constructor Insanity CSE 333 Spring 2018 Instructor: Justin Hsia Teaching Assistants: Danny Allen Dennis Shao Eddie Huang Kevin Bi Jack Xu Matthew Neldam Michael Poulain Renshu Gu Robby Marver Waylon

More information

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming Goals of Lecture Lecture 27: OO Design Patterns Cover OO Design Patterns Background Examples Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2001 April 24, 2001 Kenneth

More information

DESIGN PATTERN - INTERVIEW QUESTIONS

DESIGN PATTERN - INTERVIEW QUESTIONS DESIGN PATTERN - INTERVIEW QUESTIONS http://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm Copyright tutorialspoint.com Dear readers, these Design Pattern Interview Questions

More information

COSC252: Programming Languages: Abstraction and OOP. Jeremy Bolton, PhD Asst Teaching Professor. Copyright 2015 Pearson. All rights reserved.

COSC252: Programming Languages: Abstraction and OOP. Jeremy Bolton, PhD Asst Teaching Professor. Copyright 2015 Pearson. All rights reserved. COSC252: Programming Languages: Abstraction and OOP Jeremy Bolton, PhD Asst Teaching Professor Copyright 2015 Pearson. All rights reserved. Copyright 2015 Pearson. All rights reserved. Topics The Concept

More information

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3 Department of Computer Science Tackling Design Patterns Chapter 4: Factory Method design pattern Copyright c 2016 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 4.1 Introduction.................................

More information

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING Question No: 1 ( Marks: 1 ) - Please choose one Classes like TwoDimensionalShape and ThreeDimensionalShape would normally be concrete,

More information

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator. Comparative Study In Utilization Of Creational And Structural Design Patterns In Solving Design Problems K.Wseem Abrar M.Tech., Student, Dept. of CSE, Amina Institute of Technology, Shamirpet, Hyderabad

More information

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult

More information

Design Patterns Reid Holmes

Design Patterns Reid Holmes Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns Reid Holmes GoF design patterns $ %!!!! $ "! # & Pattern vocabulary Shared vocabulary

More information

C++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield

C++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield C++ Programming Classes Michael Griffiths Corporate Information and Computing Services The University of Sheffield Email m.griffiths@sheffield.ac.uk Presentation Outline Differences between C and C++ Object

More information

Object-oriented Programming. Object-oriented Programming

Object-oriented Programming. Object-oriented Programming 2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language

More information

Evolution of Programming Languages

Evolution of Programming Languages Evolution of Programming Languages 40's machine level raw binary 50's assembly language names for instructions and addresses very specific to each machine 60's high-level languages: Fortran, Cobol, Algol,

More information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova You reuse code by creating new classes, but instead of creating them from scratch, you use existing classes that someone else has built and debugged. In composition

More information

CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism

CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism Review from Lecture 22 Added parent pointers to the TreeNode to implement increment and decrement operations on tree

More information

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns Overview CS 2704 Topic: Design Patterns Design pattern concepts Kinds of patterns Some specific patterns Pattern resources 5/1/00 CS2704 Design Patterns 2 Design Pattern Solution to a particular kind of

More information

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

Course Data Processing Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1 Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

September 19,

September 19, September 19, 2013 1 Problems with previous examples Changes to the implementation will require recompilation & relinking of clients Extensions will require access to the source code Solutions Combine

More information

An Introduction to Object Orientation

An Introduction to Object Orientation An Introduction to Object Orientation Rushikesh K Joshi Indian Institute of Technology Bombay rkj@cse.iitb.ac.in A talk given at Islampur Abstractions in Programming Control Abstractions Functions, function

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Introduction to Object Oriented Programming. (Hebrew University, CS / Spring 2012 )

Introduction to Object Oriented Programming. (Hebrew University, CS / Spring 2012 ) Introduction to Object Oriented Programming (Hebrew University, CS 67125 / Spring 2012 ) Overview There are many important Object Oriented Design (OOD) principles Today we'll focus on several basic principles

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance

More information

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L 2 0 1 5 Introduction Now we ll talk about ways of thinking about design Guidelines for trials in trial and errors Major Design Heuristics

More information

Data Structures and Other Objects Using C++

Data Structures and Other Objects Using C++ Inheritance Chapter 14 discuss Derived classes, Inheritance, and Polymorphism Inheritance Basics Inheritance Details Data Structures and Other Objects Using C++ Polymorphism Virtual Functions Inheritance

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Example: Fibonacci Numbers

Example: Fibonacci Numbers Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers

More information

Resource Management With a Unique Pointer. Resource Management. Implementing a Unique Pointer Class. Copying and Moving Unique Pointers

Resource Management With a Unique Pointer. Resource Management. Implementing a Unique Pointer Class. Copying and Moving Unique Pointers Resource Management Resource Management With a Unique Pointer Dynamic memory is an example of a resource that is allocated and must be released. void f() { Point* p = new Point(10, 20); // use p delete

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Simple Factory Pattern

Simple Factory Pattern Simple Factory Pattern Graeme Geldenhuys 2008-08-02 In this article I am going to discuss one of three Factory design patterns. The Factory patterns are actually subtle variations of each other and all

More information

10. Object-oriented Programming. 7. Juli 2011

10. Object-oriented Programming. 7. Juli 2011 7. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Object Case Study Brain Teaser Copy Constructor & Operators Object-oriented Programming, i.e.

More information

Design Patterns Revisited

Design Patterns Revisited CSC 7322 : Object Oriented Development J Paul Gibson, A207 paul.gibson@int-edu.eu http://www-public.it-sudparis.eu/~gibson/teaching/csc7322/ Design Patterns Revisited /~gibson/teaching/csc7322/l13-designpatterns-2.pdf

More information

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1 CSCI 6234 Object Oriented Design: Frameworks and Design Patterns George Blankenship Frameworks and Design George Blankenship 1 Background A class is a mechanisms for encapsulation, it embodies a certain

More information

Industrial Programming

Industrial Programming Industrial Programming Lecture 4: C# Objects & Classes Industrial Programming 1 What is an Object Central to the object-oriented programming paradigm is the notion of an object. Objects are the nouns a

More information

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes What is an Object Industrial Programming Lecture 4: C# Objects & Classes Central to the object-oriented programming paradigm is the notion of an object. Objects are the nouns a person called John Objects

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

Reusing Classes. Hendrik Speleers

Reusing Classes. Hendrik Speleers Hendrik Speleers Overview Composition Inheritance Polymorphism Method overloading vs. overriding Visibility of variables and methods Specification of a contract Abstract classes, interfaces Software development

More information

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar Design Patterns MSc in Communications Software Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

INHERITANCE: EXTENDING CLASSES

INHERITANCE: EXTENDING CLASSES INHERITANCE: EXTENDING CLASSES INTRODUCTION TO CODE REUSE In Object Oriented Programming, code reuse is a central feature. In fact, we can reuse the code written in a class in another class by either of

More information

Common Misunderstandings from Exam 1 Material

Common Misunderstandings from Exam 1 Material Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself

More information

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak! //Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new

More information

Design Pattern and Software Architecture: IV. Design Pattern

Design Pattern and Software Architecture: IV. Design Pattern Design Pattern and Software Architecture: IV. Design Pattern AG Softwaretechnik Raum E 3.165 Tele.. 60-3321 hg@upb.de IV. Design Pattern IV.1 Introduction IV.2 Example: WYSIWYG Editor Lexi IV.3 Creational

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object

More information

Procedure and Object- Oriented Abstraction

Procedure and Object- Oriented Abstraction Procedure and Object- Oriented Abstraction Scope and storage management cs5363 1 Procedure abstractions Procedures are fundamental programming abstractions They are used to support dynamically nested blocks

More information

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4 CS32 - Week 4 Umut Oztok Jul 15, 2016 Inheritance Process of deriving a new class using another class as a base. Base/Parent/Super Class Derived/Child/Sub Class Inheritance class Animal{ Animal(); ~Animal();

More information

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it Design Patterns The Gang of Four suggests a few strategies for creating good o-o designs, including Façade Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it One

More information

Where do we go from here?

Where do we go from here? Where do we go from here? C++ classes and objects, with all the moving parts visible operator overloading templates, STL, standards, Java components, collections, generics language and performance comparisons

More information

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm Assignment 2 Solutions This document contains solutions to assignment 2. It is also the Marking Rubric for Assignment 2 used by the TA as a guideline. The TA also uses his own judgment and discretion during

More information

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 9 OO modeling Design Patterns Structural Patterns Behavioural Patterns

More information