Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Post on 21-Jan-2016

217 views 0 download

Tags:

Transcript of Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Cramming for CS 247

FAQ

• Q: Will you post these slides online?

• A: Yes.

Single ADT Design

02 - Classes in C++

• ADTs, Classes, Objects• Constructor• Destructor• Private vs public• Friends

03 – Design decisions for a single class

• Should we write a constructor?• Should the constructor be explicit?

class Stack{public:

explicit Stack(int size);};

03 – Design decisions for a single class

• Accessor and Mutatorclass Integer{

int x;public:

void setX(const int x);int getX() const;

};

03 – Design decisions for a single class

• Operator overloadingclass Integer{

int x;public:

Integer operator+ (const Integer &y) const;};

04 – Consts and References

• int *p;• const int *p;• int const *p;• int *const p;• const int *const p;

05 – Copy constructor

• Purpose: Duplicating an existing object

• How copy constructors work• How operator= works• How operator== works

• More design decisions

Multiple ADT Design

06 – Modules

• .h files contain DECLARATIONS• .cpp files contain DEFINITIONS

• The “make” command• Makefile

06 – Modules

• Namespaces• What does “using namespace” std mean?

08 – UML Diagrams

• Visual representation of ADTs

class Integer{int x;

public:void setX(const int x);int getX() const;

}

Integer

- x : int

+ setX(int)+ getX() : int

08 – UML Diagrams• Arrows : navigability

A has a pointer to B

• Numbers : multiplicity

A has 2 instances of B

A B

A B2

08 – UML Diagrams

A and B are related

B is part of A

B is part of A, and B cannot exist without A

A B

A B

A B

09 – Aggregation and Composition

How to code aggregation

and composition

in C++

A B

A B

10 - Inheritance

• Creating new classes based on previous onesclass Animal {public: void walk();};

class Cat : public Animal {public: void purr();};

Animal has 1 function:walk

Cat has 2 functions:purrwalk

11 - Polymorphism

• Allowing objects to take many forms

• Animal *a = new Animal(); //OK• Animal *b = new Cat(); //Also OK

• Function override, virtual functions

12 – Design principles

• What CAN we inherit?• What SHOULD we inherit?• HOW should we inherit?

• Inheritance vs Composition

Program Maintenance

07 - Testing

• What is unit testing?• System vs Integration testing• What is boundary testing?• Black box vs white box testing

• Assert function

15 - Debugging

• Using the GDB debugger• Debugger commands

14 - Exceptions

• try and catch syntax in C++

• More design principles– When SHOULD we try and catch?– When SHOULDN’T we try and catch?

Design Patterns

16 – 19 - Design Patterns

• An algorithm is a standard step-by-step routine for solving a problem (e.g. quicksort)

• A data structure is a standard organization of data in memory (e.g. linked list)

• A design pattern is a standard object-oriented architectural layout (e.g. strategy pattern)

16 – 19 - Design Patterns

• Strategy Pattern

SortStrategysort()

Quicksortsort()

Mergesortsort()

SortedArraysort()

Element*

16 – 19 - Design Patterns

• Strategy Pattern• Template Method• Factory Method• Observer Pattern• Model View Controller• Composite Pattern• Iterator Pattern• Decorator Pattern

STL

20 - Templates

• Classes that support multiple data types template <typename T> class Stack{ … };• Stack <int> integerStack;• Stack <float> floatStack;

21 – Generic Algorithms in STL

• #include <algorithm>– copy– find

• #include <iterator>• #include <functional>

21 – Generic Contains in STL

• #include <vector>• #include <deque>• #include <list>• #include <set>• #include <map>

• More STL iterators