Duke CPS 108 2. 1 Why C++? l a better C ä type safe, e.g., I/O streams ä better support for ADTs, encapsulation l object-oriented programming ä add inheritance.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Advertisements

Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Visual Basic: An Object Oriented Approach 11 – Patterns in object oriented programming.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Design Patterns Ref : Chapter 15 Bennett et al. useful groups of collaborating classes that provide a solution to commonly occuring problems. provide.
C++ Polymorphism Systems Programming. Systems Programming: Polymorphism 2   Polymorphism Examples   Relationships Among Objects in an Inheritance.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
OO Frameworks Department of Computer Science Kent State University.
Design Patterns.
Introduction to Object-oriented programming and software development Lecture 1.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSE 332: Design Patterns (Part I) Introduction to Design Patterns Design patterns were mentioned several times so far –And the Singleton Pattern was discussed.
“A labor of love” (Multicast Pattern) Chapter 4 (pages or ) Chris Gordon.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Class Relationships Lecture Oo10 Dependencies. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 5 p.69, Chapt 9 130, Chapt 10.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
CSE 403, Spring 2008, Alverson Software Design “There are two ways of constructing a software design: one way is to make it so simple that there are obviously.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Chapter 17 – Object- Oriented Design. Chapter Goals To learn about the software life cycle To learn about the software life cycle To learn how to discover.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
CPS Inheritance and the Yahtzee program l In version of Yahtzee given previously, scorecard.h held information about every score-card entry, e.g.,
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
Software Design 1.1 CPS 108, Spring 2006 l Object oriented programming and design, we'll use Java and C++  Language independent concepts including design.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Duke CPS CPS 108, Spring 1998 l Software Design and Implementation ä Object oriented programming and design ä good design helps do away with late.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CSC 143 O 1 CSC 143 Inheritance and Object Oriented Design.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Examples (D. Schmidt et al)
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Design Patterns with C# (and Food!)
object oriented Principles of software design
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Informatics 122 Software Design II
Presentation transcript:

Duke CPS Why C++? l a better C ä type safe, e.g., I/O streams ä better support for ADTs, encapsulation l object-oriented programming ä add inheritance to encapsulation ä OO isn’t a silver bullet, but it helps in dealing with the complexity of software development l non OO programming ä sometimes non-class approach has merits l generic programming ä STL, the standard template library

Duke CPS Why inheritance? l standard shape example ä difficult to extend ä access to source ä change all functions ä what is state? l inheritance ä models is-a Liskov substitution principle ä cost? (who pays?) double Shape::area() const { switch (myKind) { case Shape::circle: return PI * myDim * myDim; case Shape::square: //... } class Shape { public: enum Kind {circle,square,...}; double area() const; void rotate(); private: Kind myKind; };

Duke CPS Inheritance l virtual functions provide runtime polymorphism ä must use pointers or references ä can extend base class without access to source l in C++ there are several kinds of inheritance ä public, private, virtual,... ä multiple inheritance l we’ll use single, public inheritance, trying to model “is-a” as much as possible l General goal: base classes are abstract, have one pure virtual function ä model an interface, not an implementation ä see roulette program for example, also map hierarchy

Duke CPS shapes: C++ features, what is “is-a”? class Shape { public: virtual double area() const = 0; }; class Square : public Shape { public: virtual double area() const {return mySide * mySide;} private: double mySide; }; class Rectangle : public Shape { public: virtual double area() const {return myWidth * myHeight;} };

Duke CPS Designing for change (extension) l How does inheritance help? l What about different table formats in hyperwag? ä is more than one layout possible? problems? if (headerStyle == normal)... else if (headerStyle == gaudy)... else if... l factory pattern helps here ä abstracts object creation, multiple look-and-feel ä can use factory for reading format, writing format,...

Duke CPS Factory Pattern l Consider classes for different look-and-feel styles NormalLayout wagNL;wagNL.makeHeader(); GaudyLayout wagGL;wagGL.makeHeader(); ä problems, how to choose styles, when to choose l Does inheritance help? (assume ABC, Layout) Layout * wag = new NormalLayout; Layout * wag = new GaudyLayout; wag->makeHeader(); ä is this better? are there problems? l Use a Layout Factory Layout * wag = factory->makeLayout(); wag->makeHeader(); ä dependencies exist, but in factory ä parameters to factory can set the look-and-feel returned

Duke CPS Design patterns l Add to vocabulary we use to communicate and think about design l Form part of a tool-kit we use when thinking about design l Help find solutions to design problems ä factory ä iterator see usewords.cc ä proxy ä also: adapter, singleton, observer, command ä also: model-view-controller, client-server, … ä GOF, gang-of-four, Gamma, Helms, Johnson, Vlissides ä we’re using Buschmann et al

Duke CPS usewords.cc l iterators ä internal, external ä creation/deletion ä use of inheritance and naming conventions l STL, Duke-classes ä what is a templated class/function? ä how are templates instantiated? ä drawbacks?

Duke CPS Data Structures, STL, Generic Programming l common container classes/data structures ä vector growable array ä map dictionary, (seach tree, hashtable) ä set union, intersection, membership l STL, Standard Template Library ä not just implemenations, but way of thinking ä little/no inheritance, lots of templates ä algorithms and functions generalized too l default often not-safe, implementations make heavy use of “new C++ features”

Duke CPS Thinking about thinking about hyperwag l issues in specification ä ambiguities ä missing pieces l classes: nouns; member functions: verbs ä what, not how ä responsibilities and collaboration among classes l other design/problem questions?

Duke CPS Designing Classes and Programs l Where do classes come from? ä nouns: brainstorm, cull, combine, divide ä attributes vs. classes, keep cohesion high l Things to watch out for ä kitchen sink classes: keep classes highly cohesive ä God classes: know about everything in the app ä classes with little behavior (only get/set), and few collaborators l CRC cards: classes, responsibilities, collaborators ä 3x5 card, class name at top, list responsibilities and collaborators

Duke CPS CRC card template Class name subclasses/superclasses responsibilitiescollaborators WagReader (abstract) parseStream getAppointment? iterators?... Appointment Stream WagMaker... Other classes in hyperwag?

Duke CPS working in groups/teams l work together/debate the design, don’t code until the design is understood by everyone ä what about initial hyperwag prototype? ä Doom: Design and implementation are iterative processes l what about controlling the source code, building the program? ä use RCS or CVS, start now (hopefully CVS soon, see web) ä build/make everyday, versions ok, a working program is a wonderful thing ä who’s in charge?

Duke CPS Brooks’ team (see chapter 3, Mythical Man Month) l surgeon, chief programmer l copilot l administrator l editor l program clerk l toolsmith l tester l language lawyer l secretaries (2) ä necessary? what about three-person teams

Duke CPS Other team formats l Everyone participates in design l Everyone codes l Someone has to be in charge l What about different views, levels of experience? l What can be done when someone doesn’t deliver? l How to live with the team (or not) l What’s the best way to get everyone to help? l Don’t leave anyone behind, don’t get left behind