Introduction to Design Patterns
|
|
- Thomasina Wheeler
- 6 years ago
- Views:
Transcription
1 Introduction to Design Patterns First, what s a design pattern? a general reusable solution to a commonly occurring problem within a given context in software design It s not a finished design that can be transformed directly into code It is a description or template for how to solve a problem that can be used in many different situations. patterns are formalized best practices that you must implement yourself in your application Design patterns gained popularity after the book Design Patterns: Elements of Reusable Object- Oriented Software was published in 1994 by the so-called "Gang of Four" (Gamma et al.).
2 Structural Some Kinds of Design Patterns These ease the design by identifying a simple way to realize relationships between entities. Behavioral These identify common communication patterns between objects and realize these patterns Creational These deal with object creation mechanisms, trying to create objects in a manner suitable to the situation And there are others
3 The Flyweight Design Pattern The intent of this pattern is to use sharing to support a large number of objects that have part of their internal state in common where the other part of state can vary. This one is a structural pattern the structural relationship between specific and shared state is what is central in this pattern When do we use a flyweight? When a class has many instances and they can all be controlled identically Classic example of the Flyweight pattern: the representation of a character in a word processor Rather than each character having separate glyph objects that represent the font and formatting data, each character could have a reference to a flyweight glyph object shared by every instance of the same character in the document. Then the character itself would need only to store it's position in the document and the reference to the glyph, rather than it's entire formatting information.
4 The Flyweight Pattern How does it Work? Intrinsic state is what makes a given object unique (the glpyh for a character) Extrinsic state is information that can be passed in through arguments the character s position in the document) The Flyweight interface declares methods which flyweight instances can receive and use extrinsic data. The FlyweightFactory is responsible for the creation and management of the flyweights, ensuring that they are shared properly. If the desired Flyweight isn't created yet it will create and return one. Otherwise, it will return one from the current pool of flyweights. Often it s an indexer. A ConcreteFlyweight object adds capabilities for intrinsic state. The Client is your application program
5 The Strategy Pattern Intent: Define a family of algorithms, encapsulate each one, and make them interchangeable. Capture the abstraction in an interface, bury implementation details in derived classes. This one is a behavioral pattern the interface idealizes the behavior Interface could be: an abstract base class In this case, we have dynamic polymorphism the method signature expectations by the client In this case, the Interface entity represents template code and the inheritance hierarchy represents static polymorphism
6 The Strategy Pattern How does it Work? Define an interface that is common to all aspects of some behavior This could be a pure virtual function in a base class or a template function with its parameterized signature Define algorithms specific to particular instances of that behavior These could be concrete functions that implement the base class s pure virtual function (or the parameterized code of the template function) The client code creates a context in which a specific concrete algorithm is invoked that is appropriate in the runtime context The client code makes use of a pointer to base class to refer to a derived class object and then the proper binding of concrete method to function call (or the binding to type of argument) is done at runtime
7 The Factory Pattern Intent: creates objects without exposing the instantiation logic to the client. refers to the newly created object through a common interface (i.e. a pointer to base) This one is a creational pattern uses <<interface>> Product Concrete Product Client creates Factory ask for a new object +createproduct():product How you use it: The client needs a product, but instead of creating it directly using the new operator, it asks the factory object for a new product, and gives the info about the type of object it needs. The factory instantiates a new concrete product and then returns the newly created product (casted to abstract product class) to the client. The client uses the products as abstract products without being aware about their concrete implementation.
8 The Factory Pattern How does it Work? An example: You have a graphical application works with shapes. The drawing framework is the client and the shapes are the products. All the shapes are derived from an abstract Shape class (or interface) that defines abstract draw and move operations which must be implemented by the concrete shapes. Suppose that a command is selected from a menu to create a new Circle. The drawing framework receives the shape type as a string parameter and it asks the factory to create a new shape, sending the parameter received from menu. The factory creates a new Circle and returns it to the framework, as a pointer to the base abstract class Shape. Then the framework uses the pointer to base without being aware of the concrete object type. New shapes can be added without changing a single line of code in the framework (the client code that uses the shapes from the factory). uses <<interface>> Product Concrete Product Client creates Factory +createproduct():product ask for a new object
9 When should Factory be Used? The Factory pattern allows you to create objects without being bothered by what the actual class being created is. The benefit is that the client code (calling code) can just say "give me an object that can do XYZ" without knowing what is the actual class that can do "XYZ". Use Factory when a class can't anticipate the exact class of objects it must create. a class wants its subclasses to specify the objects it creates. classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate.
10 Let s put this to use: The Game of Set Set is a card game The object of the game is to identify a Set of 3 cards from 12 cards laid out on a table Each card has: A Color (red, green, or blue) A Symbol (oval, squiggle, or diamond) A Number (1, 2, or 3 Symbols) Shading (solid, open, or striped) A Set consists of EITHER 3 cards with the condition: each of the features is the same on each card OR is different on each card When a set is found, those cards are removed and replaced by three new cards from the deck The deck is made up of 81 distinct cards The game continues until the deck is gone
11 These 3 are a Set Some Examples of Sets They all have 2 ovals so they agree on Symbol and on Number They are all of different Colors They are all of different Shading L17 Feb. 24, 2010 friends and software reuse
12 These 3 are a Set Some Examples of Sets They all have the same Color and the same Shading They are all of different Symbols They are all of different Numbers L17 Feb. 24, 2010 friends and software reuse
13 What would a typical game table look like? Where are the sets? Color Number Symbol Shading L17 Feb. 24, 2010 friends and software reuse
14 How would we design a program to play a solitaire game of Set? What is the basic object we have to deal with? The card What are the operations that we need to do with cards? Display them on the screen Check a collection of 3 of them to see if they form a Set What do we know about the properties (features) of an individual card? There are four features: Color, Number, Symbol, Shading For a given card, these features do not change
15 What does this suggest as a class for card? enum Color = {red, blue, green}; class Card { public: <some methods here, not sure what yet> private: Color col; Num num; Symbol sym; Shading shade; }; What functionality is critical for the class Card? We need to be able to determine if three cards form a set This means that we need to be able to check their features for equality Two cards with squiggle symbol need to have their Symbol attributes equal Two cards with striped shading need to have their Shading attributes equal, even if one has 2 striped red ovals and the other has 3 striped green diamonds How can we do this? One solution: write an equals() method for each attribute Problem: this will work, but it is very tedious One equals() method for each of the attributes We ll need at least one constructor and a destructor And the card needs to be able to draw itself There is a simpler way to do this
16 How do design patterns come into play? class Card { public: Card(); Card (Color c, Num n, Symbol sy, Shading sh); draw(); private: Color col; Num num; Symbol sym; Shading shade; }; We need to look at these objects that represent the 4 attributes each Card has
17 Color Each card is assigned a Color This color is used for two things: To draw the symbol in a particular color To do the fill in the symbol (if solid or striped, it should be of that color, assuming a graphical world) Our base assumptions are that Color will have one of three values: Red Blue Green So we make a class Color with an attribute that indicates the color and with methods that will let us construct a Color object, set its data value, and retrieve its data value
18 The class Color class Color { public: Color(); Color (int c); int get_color(); void set_color(int c); bool operator == (Color &c) private: int col; } How many Color objects are we going to need? Here s where we use the flyweight!! Make 3 Color objects and let the cards share them L17 Feb. 24, 2010 friends and software reuse Color::Color() { col = 15; // default color is white } Color::Color (int c) { col = (c % 16); // color is between 0 and 15 } int Color::get_color() { return (col); } void Color::set_color(int c) { col = (c % 16); } bool Color:: operator == (Color &c) { return (col == c.col;) }
19 Number The Number attribute says how many Symbols are on the card In a general implementation, it also indicates where each of the symbols should be drawn If there is 1 symbol, it is in the middle If there are 2 or 3, they are centered in the card vertically The idea is that all cards with, say, 3 symbols on them will draw them in the same relative position on the card This means that it will not work to have the Number be a simple integer (1, 2, or 3). It needs to be a vector of (x,y) locations Then the number of symbols is the length of the vector How many numbers do we need? Three, so use the Flyweight here, too!!
20 Symbol The symbol (in a general graphical game) is a shape We could indeed think of a symbol as a string or a character What is the most important thing a symbol has to do? Know how to draw itself So its most important method would be a draw() method But each symbol will be drawn differently! That means that each symbol has to belong to its own class so that the draw method for it can be specific to it. And each card also has a shading associated with it, so the draw method should have a shading argument: draw(shading s)
21 Class Structure for Symbol The draw method for a Symbol is polymorphic the draw method of the base class Symbol would be a pure virtual method and the derived classes would display the proper symbol
22 Using the Attributes of a Card We ve discussed three of the attributes: Color Number Symbol We haven t yet talked about Shading, but that s for a reason: it can be more complicated The role of the attributes is To use in checking whether a group of 3 Cards makes a Set Turns out this is pretty easy To use when the Card draws itself The Card has to use the Color and the Number (with its vector of locations) to guide the drawing, but it s going to delegate the job of actually drawing the shapes to Symbol
23 Checking to see if we have a Set We can make a method for the class Card like this: bool Card::isSetSymbol (Card c1, Card c2, Card c3) { } If (c1.sym == c2.sym && c2.sym == c3.sym) (c1.sym!= c2.sym && c1.sym!= c3.sym && c2.sym!= c3.sym) return true; else return false; And we make similar methods issetnumber, issetcolor, and issetshading Then we can easily tell if a collection of 3 cards is a Set
24 What about drawing the card? The Card uses the Color and the Number (with its vector of locations) to guide the drawing, but remember that it s going to delegate the job of actually drawing the shapes to Symbol But remember that the concept of having an algorithm delegate responsibility for some part of its function to some helper object is called the Strategy Design Pattern This simplifies the card s draw code But to do it, we do have to define the abstract class Symbol and its derived classes Diamond, Oval, and Squiggle
25 Pseudocode for drawing the Card Remember that we have: Card with its private members col, num, sym, and shade The class Symbol has a draw method, and we ll let that draw method have a single argument: a Shading void Card::draw() { setcolor (col); //set the display color to the Color attribute of the Card for each( location in num) { sym.draw (shade); } }
26 Now let s return to the Shading feature What does this feature really DO? If the application is a graphical one, it designates the fill color and texture of the shape, once colored If open, the fill is the background color If solid, the fill is the display color If striped, the fill is a texture of the display color If the application is a console application, it has to be something else! Turns out, we can set background color and text color independently So if we have a console app, we can let the Shading determine the background color Accomplishing the task of displaying the card by using the draw method of Symbol as our work horse tool lets us hide the implementation details We make the Shading feature be represented by a base class Shading with derived classes Solid, Open, and Striped This class hierarchy has an abstract method getpaint() that each of the derived classes overrides to make the concrete class We can change the nature of the visual display easily by just changing the getpaint() methods of the Shading derived classes!
27 Factory Pattern This is an example of using another design pattern The Factory Pattern Remember that this pattern has an object return an instance from a family of related classes that meet this particular class s needs A factory is an object for creating other objects The idea is to define an interface (abstract class) for creating an object, but let the classes which implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses
28 So how do we change colors? In Visual Studio, the text color and the background color can be (somewhat independently) set: There are 16 colors, and each has a number: BLACK = 0, BLUE = 1, GREEN = 2, CYAN = 3, RED = 4 MAGENTA = 5, BROWN = 6, LIGHTGREY = 7, DARKGREY = 8, LIGHTBLUE = 9, LIGHTGREEN = 10, LIGHTCYAN = 11, LIGHTRED = 12, LIGHTMAGENTA = 13, YELLOW = 14, WHITE =15 The color of the text and background is determined using the following formula: colorattribute = foreground + background * 16 to get red text on yellow use *16 = 228 light red on yellow would be *16 = 236 Bottom line is that you can easily write the draw method for a console application!!
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 informationProgramming 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 informationCSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich
CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and
More informationSoftware 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 informationChapter 14 Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationInheritance. 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 informationI BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++
No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)
More informationObject-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 informationC++ Inheritance and Encapsulation
C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members
More informationIntroduction 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 informationCpt S 122 Data Structures. Course Review Midterm Exam # 2
Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm
More informationAn 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 informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationData 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 informationECE 3574: Dynamic Polymorphism using Inheritance
1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:
More informationJava 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 informationCS 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 informationTopics 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 informationDesign Patterns: State, Bridge, Visitor
Design Patterns: State, Bridge, Visitor State We ve been talking about bad uses of case statements in programs. What is one example? Another way in which case statements are sometimes used is to implement
More informationCS11 Introduction to C++ Fall Lecture 7
CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationIncreases Program Structure which results in greater reliability. Polymorphism
UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the
More informationCSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich
CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and
More informationCSE 70 Final Exam Fall 2009
Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15
More informationObject Oriented Paradigm
Object Oriented Paradigm Ming-Hwa Wang, Ph.D. Department of Computer Engineering Santa Clara University Object Oriented Paradigm/Programming (OOP) similar to Lego, which kids build new toys from assembling
More informationVIRTUAL FUNCTIONS Chapter 10
1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions
More informationTHOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS
THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS LOGISTICS HW3 due today HW4 due in two weeks 2 IN CLASS EXERCISE What's a software design problem you've solved from an idea you learned from someone else?
More informationLecture 13: Design Patterns
1 Lecture 13: Design Patterns Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2005 2 Pattern Resources Pattern Languages of Programming Technical conference on Patterns
More informationModellistica 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 informationPattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository
Pattern Resources Lecture 25: Design Patterns Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Pattern Languages of Programming Technical conference on Patterns
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationInheritance (IS A Relationship)
Inheritance (IS A Relationship) We've talked about the basic idea of inheritance before, but we haven't yet seen how to implement it. Inheritance encapsulates the IS A Relationship. A String IS A Object.
More informationFactory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate
Factory Method Pattern Creational Intent» Define an interface for creating an object but lets subclasses decide the specific class to instantiate > Delegate creation to the appropriate subclass Also known
More informationCS250 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 informationadministrivia today UML start design patterns Tuesday, September 28, 2010
administrivia Assignment 2? promise to get past assignment 1 back soon exam on monday review slides are posted your responsibility to review covers through last week today UML start design patterns 1 Unified
More informationObject-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 informationObject-Oriented Programming
Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object
More informationLecture 5: Inheritance
McGill University Computer Science Department COMP 322 : Introduction to C++ Winter 2009 Lecture 5: Inheritance Sami Zhioua March 11 th, 2009 1 Inheritance Inheritance is a form of software reusability
More informationChapter 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 informationDesign 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 informationSoftware 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 informationC++ 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 informationInheritance (Outsource: )
(Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,
More informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship The "is-a" Relationship Object classification
More informationGoals 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 informationObject-Oriented Programming
iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 40 Overview 1 2 3 4 5 2 / 40 Primary OOP features ion: separating an object s specification from its implementation. Encapsulation: grouping related
More informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship Object classification is typically hierarchical.
More informationOBJECT 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 informationCS201 - 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 informationA few important patterns and their connections
A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Plan Singleton Factory method Facade and how they are connected. You should understand how to
More informationPlan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade
Plan A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Singleton Factory method Facade and how they are connected. You should understand how to
More informationJAVA GUI PROGRAMMING REVISION TOUR III
1. In java, methods reside in. (a) Function (b) Library (c) Classes (d) Object JAVA GUI PROGRAMMING REVISION TOUR III 2. The number and type of arguments of a method are known as. (a) Parameter list (b)
More informationWhat 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 informationOBJECT ORİENTATİON ENCAPSULATİON
OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual
More informationQUIZ. How could we disable the automatic creation of copyconstructors
QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance
More informationOBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism http://en.wikipedia.org/wiki/encapsulation_(object-oriented_programming)
More informationPolymorphism 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 informationCS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I 2-marks ) Give some characteristics of procedure-oriented language. Emphasis is on doing things (algorithms). Larger programs are divided
More informationIntroduction to Software Engineering: Object Design I Reuse & Patterns
Introduction to Software Engineering: Object Design I Reuse & Patterns John T. Bell Department of Computer Science University of Illinois, Chicago Based on materials from Bruegge & DuToit 3e, Chapter 8,
More informationSDC Design patterns GoF
SDC Design patterns GoF Design Patterns The design pattern concept can be viewed as an abstraction of imitating useful parts of other software products. The design pattern is a description of communicating
More informationPOLYMORPHISM Polymorphism: the type Polymorphism taking many shapes type of object
1 License: http://creativecommons.org/licenses/by-nc-nd/3.0/ POLYMORPHISM There are three major concepts in object-oriented programming: 1. Encapsulation (Classes), Data abstraction, information hiding
More information5.6.1 The Special Variable this
ALTHOUGH THE BASIC IDEAS of object-oriented programming are reasonably simple and clear, they are subtle, and they take time to get used to And unfortunately, beyond the basic ideas there are a lot of
More informationShort 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 informationPolymorphism. Zimmer CSCI 330
Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e 1992-2010 by Pearson Education, Inc. All Rights Reserved. 1 Standard Behavior: When the compiler is working out which member function to call, it selects according to the type of
More informationObject 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 informationClient Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module
Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as
More information1. Write two major differences between Object-oriented programming and procedural programming?
1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:
More information1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides
1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of
More informationCS 162, Lecture 25: Exam II Review. 30 May 2018
CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you
More informationA - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models
CS 494 Object-Oriented Analysis & Design UML Class Models Overview How class models are used? Perspectives Classes: attributes and operations Associations Multiplicity Generalization and Inheritance Aggregation
More informationEssential Skills for the Agile Developer. Agile. copyright Net Objectives, Inc.
Essential Skills for the Agile Developer Agile copyright 2010. Net Objectives, Inc. Lean for Executives Product Portfolio Management Business Lean Enterprise ASSESSMENTS CONSULTING TRAINING COACHING Team
More informationUNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED
UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED EXERCISE 11.1 1. static public final int DEFAULT_NUM_SCORES = 3; 2. Java allocates a separate set of memory cells in each instance
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More information4.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 informationCS 1316 Exam 1 Summer 2009
1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 1 Summer 2009 Section/Problem
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #34 Function with pointer Argument (Refer Slide Time: 00:05) So, here is the stuff that we have seen about pointers.
More informationObject 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 informationDesign Patterns. Dr. Rania Khairy. Software Engineering and Development Tool
Design Patterns What are Design Patterns? What are Design Patterns? Why Patterns? Canonical Cataloging Other Design Patterns Books: Freeman, Eric and Elisabeth Freeman with Kathy Sierra and Bert Bates.
More information(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University
(12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables
More informationDesign 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 informationICS 4U. Introduction to Programming in Java. Chapter 10 Notes
ICS 4U Introduction to Programming in Java Chapter 10 Notes Classes and Inheritance In Java all programs are classes, but not all classes are programs. A standalone application is a class that contains
More informationInheritance, 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 informationThe Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?
Page 1 of 21 Page 2 of 21 and identity. Objects are members of a class, and the attributes and behavior of an object are defined by the class definition. The Essence of Object Oriented Programming with
More informationIT101. Inheritance, Encapsulation, Polymorphism and Constructors
IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable
More informationInheritance, Polymorphism and the Object Memory Model
Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation
More information02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211
02 Features of C#, Part 1 Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 Module Overview Constructing Complex Types Object Interfaces and Inheritance Generics Constructing
More informationDESIGN 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 information9/21/2010. Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh
Building Multitier Programs with Classes Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh The Object-Oriented Oriented (OOP) Development Approach Large production
More information2. The object-oriented paradigm!
2. The object-oriented paradigm! Plan for this section:! n Look at things we have to be able to do with a programming language! n Look at Java and how it is done there" Note: I will make a lot of use of
More informationChapter 10 Classes Continued. Fundamentals of Java
Chapter 10 Classes Continued Objectives Know when it is appropriate to include class (static) variables and methods in a class. Understand the role of Java interfaces in a software system and define an
More informationDesign of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts
Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference 2015-2016 Visitor See lecture on design patterns Design of Software Systems 2 Composite See lecture on design patterns
More informationItem 4: Extensible Templates: Via Inheritance or Traits?
ITEM1_11new.fm Page 1 Tuesday, November 27, 2001 12:49 PM Item 4: Extensible Templates: Via Inheritance or Traits?. ITEM 4: EXTENSIBLE TEMPLATES: VIA INHERITANCE OR TRAITS? DIFFICULTY: 7 This Item reviews
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationJava Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding
Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance
More informationModule 10 Inheritance, Virtual Functions, and Polymorphism
Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:
More informationAbstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.
a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationSimple 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