CS3307 - UWO - Object-Oriented Design and Analysis - Fall 2017

Ace your homework & exams now with Quizwiz!

What C++ expressions and operators does C++ have?

Arithmetic operators +,-,*,/,% Comparison operators ==,!=,<,>,<= and >= Assignment and initialization operator =

What kinds of things can you find in the standard template library?

Containers, algorithms and iterators oh my!

What is INVEST

Invest is an acronym that can help develop good stories: It stands for (I)ndependent, (N)egotiable, (V)aluable, (E)stimatable, (S)mall, (T)estable

What is overloading

It allows you to have more than one definition for a function or operator in the same scope. If they have the same name they will have different arguments and implementations. Compiler determines appropriate one based on args. This extends to member functions. It cannot only differ by return.

What is the conversation?

It develops the details of a particular story, it should be done just in time.

How does the virtual keyword affect polymorphism?

It enables dynamic dispatching. virtual is expressed in the header and a method declared virtual will stay virtual in all descendant classes. virtual should be placed on a parent class function which is expected to be overridden. virtual methods can also be left unimplemented, this is called abstract in other languages. This forces subclasses to implement. e.g. virtual void sayHello() = 0;

In what ways does a function exit?

It executes a return statement providing a return value or nothing in the case of void. Reaching the end of the body in a void function or main() Calling a system function that does not return (like exit()) Exception throwing and handling can also cause a function to exit.

What is an iteration?

It is a period of time, during which developers are expected to deliver some subset of the application.

Why is the this keyword used?

It is a pointer that refers to the current object to self reference. It makes code more readable.

What is Procedural Programming?

Procedural programming is structured oriented around procedures (also known as functions, routines, or subroutines) which accept data, usually as parameters

Abstraction

Refers to modelling an entity so only critical characteristics are presented

Describe Information Hiding

Refers to shielding and hiding of design and implementation details Interact through published interface

What is Model View Presenter

Related to MVC, decouples model and view (MVP)

Describe the control flow of a program in C++

Similar to C, one statement to the next, with repetition and selection until completion

What is meant by the design principal ENCAPSULATE WHAT VARIES?

Take parts that vary and encapsulate them so later you can alter or extend the parts without affecting other parts The eliminates code duplication Allows code reuse Can modify existing behaviours instead of larger class and change at run-time

Describe the use of pointers in C++

There are 2 main usages: - referring to memory allocated dynamically off the heap using (malloc() or new). When passing large chunks of data to a function or method, passing a pointer can be more efficient, as it reduces copying and speeds up processing

How many types of Behavioral Classes are there?

There are two: Class Behavioral use inheritance to distribute behavior between classes Object Behavioral uses composition

What is Unified Modeling language?

Unified modelling language is a modelling language that unified many predecessors to describe a high level of software abstraction.

What is a UML realization?

Used in the duck example in class, when a class implements a pure virtual class it is a realization denoted by a broken line with a full arrow

Valuable

User stories should be valuable to the users, customers and developers Written so the benefits to the customers / users are apparent This story prioritization by customers

What is used for file I/O?

ofstream - output file stream class ifstream - input file stream fstream - class to read and write

How do you use the iostream input and output stream objects?

cout - outputs to terminal cin accepts from terminal keyboard like stdin cerr outputs to terminal, except generally no buffereing. Standard C I/O is still possible but programmers are encouraged to use C++ I/O Key is operators << (insertion) for output >> (extraction) for input

What are the 4 main components of a design pattern?

Name Problem Description Solution Description Consequences

Constant usage examples:

#define PI 3.14 constexpr double circleArea(double x) {return PI*x*x;}

Sample File I/O

#include <iostream> #include <fstream> using namespace std; int main() { string line; ifstream file; file.open("text.txt"); while (getline(file, line)) { cout << line << endl; } } /* outputs a file contents to cout*/

What is the general format for using File I/O in C++?

1 Declare the variable 2 Open the file at variable, and possibly define the type of operation 3. Carry out operations using << and >> to move data too and from file 4. Close the file

A brief history of C++

- late 70s and 80s C grew popular in variety of domains - general purpose, fast, portable and reasonably easy to use and build compilers/toolchains C did not encourage or enforce sound principals and practices for Software Engineering that were emerging

What are the problems with big design?

- cumbersome design that is tedious, error-prone and often not read fully by anyone - customers change their mind - often doesn't incorporate the the reality of time needed for development

C(o)mposition vs (A)ggregation

(O)wns-A vs H(a)s-A (First variance in comparison is the same) Black Diamond of Death vs white diamond of life complete diamond for composition

Describe a function declaration in C++

- Contain name of the function - arg or param list (could be empty) - return type (could be void) - one or more optional modifiers

How do you use a design pattern?

1. Search patterns to match your problem 2. Understand the pattern 3. Adapt and implement.

How do you discover design patterns?

1. Solve a software problem 2. Abstract and generalize the solution 3. Record the patterns for future use.

Brief History of C++ continued

2 primary contendors to OOP-C emerged in early 80s: C with classes, Bjarne Stroustrup (which was coined C++ (83) Rick Mascitti) won out Objective-C, Brad Cox/Tom Love Mac acquired NeXt 96/97 and used their Objective-C but changed it dramatically in 2014 through swift ("objective C without the C")

Statements and blocks

A block, or compound statement, is the term given to a collection of statements enclosed in {...} . defines a scope for variables declared in it; local variables are put on the stack for the duration of the execution of the block statement. declarations no longer have to be at beginning of a block

What are the main components of User Stories?

A card, with a written description of the story. A conversation to flesh out it's details. Confirmation: tests that convey and document details to confirm the story is complete.

What is a design pattern?

A description of objects and classes that are customized to solve a general design problem. Most design patterns help us to adhere to well-known design principles

What is a class tempate?

A form of generic declaration of a class. #include<iostream> using namespace std; template <class T> class calc { public: T multiply(T x, T y); T add(T x, T y); }; template <class T> T calc<T>::multiply(T x, T y) { return x*y; } template <class T> T calc<T>::add(T x, T y) { return x+y; } int main() { calc<int> c; cout << c.add(10,20) << endl; }

What does a friend mean to C++?

A friend is a function that can use the private and protected members of a class. However friendship in C++ is one-way. Of course, we all have a friend or two like that!!! So if you want it two-way you must declare it. It is also not transitive. My friends are not your friends, and your friends are not my friends. usage friend class MyClass;

What is a static function?

A function can be called without instantiating an object. They don't have a this pointer.

Describe a function definition in C++

A function definition is a function declaration alongside a presentation of the body of the function. The function body provides the code to process the parameters given as input to produce the desired return result. In a definition parameters must be named

Describe a function call

A function is called by its name, identifying parameters to pass in and specifying what to do with any value it returns. The parameters passed in must match the the function declaration types Similarly, the operation carried out on what is returned (assignment, condition, etc.) must also match the function declaration by type

What is a UML generalization?

A generalization is used to capture inheritance. Creates a parent child. Shaped like triangle two parents to one child. POINTS TO PARENTS

What is the general inheritence heirarchy?

A new class inherits members of an existing class. Existing classes are referred to as base or super classes. New classes are referred to as derived or sub classes.

What expressions and types does C++ accept?

A similar set to C, including things like bool, char, int, double, corresponding to hardware facilities of fixed size and ranges. There are others too.

What is a static member?

A static member belongs to the class, not an instance. They do not require instantiation of an object before using.

What are two special forms of association?

Aggregation and Composition Aggregation is a part-of relationship, where parts are non-essential and can exist independently Aggregation OPEN DIAMOND Composition is essential and integral, it cannot exist independent of the owner Composition CLOSED DIAMOND CANNOT

Class definitions

As classes are a type of definition, we define a variable of class type this is an instance. If we however use a pointer we must create the object using the new operator.

Are parameters in C++ passed by value or by reference?

As in C, C++ defaults to passing parameters into functions by value, but it is capable of both with the correct syntax.

What is the main concern of Behavioral Design Patterns?

Behavioral Design patterns are primarily concerned with algorithms and responsibilities between objects

Which method is better OOP or Procedural

Both engage similar flow control, call-and-return mechanisms, one uses procedures, the other (OOP) uses methods on classes and objects

Encapsulation

Bundled data and functionality accessed through well-defined interface as opposed to having things spread around program or loosely associated Promotes information hiding

How can you specify which constructor to call in a derived classes constructor?

By appending the child constructor with colon and the specific parent constructor. e.g. Child::Child(int x) : Parent(x) {...}

How is multiple inheritance instantiated?

By including more than one inherited class after the : in the derived class definition. e.g. class Mustang: public Car, public SportsCar, public Ford {... };

What is a friend function?

By including the friend keyword functions external to the class can appear as member functions.

Define the concept of constants in C++

C++ has: #define - which is replaced before compiling const - named declarations the programmer doesn't wish to change enforced by the compiler constexpr - evaluated at compile time, allowing the consts to be placed in ROM or to improve performance

How many types of structural design pattern are there?

Class Structural using inheritance to compose interfaces and implementation Object structural composes objects to realize new functionality and give added flexibility

What are the basic elements of a C++ program

Classes Methods Data members

What is the OPEN/CLOSED PRINCIPLE in SOLID?

Classes should be open for extension, closed for modification, changes can introduce bugs in inherited classes If it isn't broken don't fix it, extend it if you need it to do more Allows class behavior to changed without touching source, no risk of breaking well-tested code

What is an object?

Combination of data and functionality in one unit An instance of a class, which is an extension of the Abstract Data Type

What is a data member?

Data encapsulated in an object

What are the risks of Design Patterns

Decreases innovation May risk square peg round hole solution May adjust problem to fit pattern Reliance on patterns for novices may force abstraction and loss of knowledge of solution

What is meant by independent

Dependencies between stories should be avoided Dependencies lead to prioritization and planning problems Make estimation more difficult Need to have the flexibility to easily move stories around in the release schedule, if needed Solutions: Combine and/or reorganize dependent story components

In addition to passing a pointer, how else can a parameter be passed by reference

Designating the parameter with an & in the declaration The variable in the definition will not be local, it is an alias to the variable outside the function Use with caution

What is the main goal of a Creational Design Pattern?

Encapsulate knowledge abou which concrete class the system uses. Hide how instances of these classes are built.

What is meant by SINGLE RESPONSIBILITY in solid?

Every object in a system should have a single responsibility Reducing responsibility minimizes chances class will be changed by reducing things that can be changed, also results in high cohesion, which increases reusability, robustness and understanding

C++ History some more

Evolved over years: 89 C++2.0 multiple inherit , abstract classes, static members, templates, namespaces, exceptions 98 ISO C++98 and 03 C++03 no major changes C++11 standard library with revision as C++13, more to follow in 17 and 20 Influenced other langauges Lua, Perl, Python, PHP, Rust, Java, C#

What are function templates

Generic programming allows for one class to handle multiple types. e.g. tempate <typename T> T max(T a, T b) { if (a>b) return a; else return b; }

In software design what Cohesion is desireable?

High cohesion, which means each entity is a cohesive item, meaning everything in it is homogeneous and makes sense in its place. An example of low cohesion would be a pencil sharpener in a coffee pot.

What is the DEPENDENCY INVERSION PRINCIPLES in solid

High-level modules should not depend upon low-level modues. Both should depend upon abstractions. Abstractions should not depend on details, details should depend upon abstractions. Using the wrong direction of dependency can exponentially expand derivation and can prevent reuse of code

What are structural design patterns concerned with

How classes and objects are composed into larger structures.

What is a UML Dependency

If one class changes then another might be impacted or changed. Dependency looks like needle track marks... the pointy part is where the needle goes INdependent

What is polymorphism in C?

In C++, we are usually referring to sub-type polymorphism, in which we can make use of derived classes through base class pointers and references Generally this occurs when a pointer to the parent type is called against a derived object. e.g. int main() { Person *p; Student *s = new Student(); s->sayHello(); p = s; p->sayHello(); }

What is meant by the design principal FAVOUR COMPOSITION OVER INHERITANCE?

In heritance establishes an IS-A relationship, composition/aggregation establishes a HAS-A relationship. Creating systems of composition creates flexibility, encapsulates algorithms in their own set of classes, eases extension to new behaviours, reduces code duplication and can change behaviour at run-time if you need it in another class consider delegation instead of inheritence

Which software engineering principals does OOP address?

Information/data hiding Encapsulation Abstraction Modularization

What is a copy constructor

It is a special constructor that permits objects to be copied from one to another. A default copy constructor generally exists. It is distinguished from other constructors by its recursive parameter passed by reference with const to prevent modification. e.g. Point::Point(const Point &p){ ...}

What is a destructor?

It is a special function that is automatically called whenever an object of this class is being destroyed. i.e. delete is used or function returns A destructor allows the class to deallocate storage destructors are not implicitly required (a blank one is default created)

What is a constructor?

It is a special function that is called whenever a new object of this class is created. The constructor is not strictly required but should be used to initialize objects.

What is inheritance?

It is one of the most important concepts of OOP, it allows us to define a class in terms of another permitting code reuse.

What is a change of scope?

It is when the requirements are changed in a project.

What is the purpose of the access-specifier in inheritance?

It overrides the super classes access-specifiers providing the inheritance access-specifier is more access-restrictive

What is an Association in UML

It represents a relationship between classes. Can be unidirectional or bi-directional Can be annotated with a name for the association or roles that are associated Can have cardinality

In software design what coupling is desirable?

Low Coupling is the goal leads to info hiding and encapsuation, stable interfaces and better maintainability Means data is only shared through parameters and returns Events or messages passed

What is meant by the INTERFACE SEGREGATION PRINCIPLE in SOLID

Many client-specific interfaces are better than one general purpose one. Clients should not depend on interfaces that they do not use. C++ allows multiple inheritence use it.

What is MVC

Model-View-Controller is a behavioural design pattern (though arguably architectural) Model encompasses data classes computation, persistence View encompasses UI components Controller encompasses application logic/functionality Reduces coupling, increases cohesion

Name 3 Benefits of OOP

Models elements of the real world Employs Software Engineering principals Integrates better with other programs and libraries through agreed upon standardized interfaces

Describe the main structure of a C++ program

Most made up of multiple classes A main acts as entry point (bootstrap) only one can exist per program

Can operators be overloaded?

Most of the built-in operators can be overridden. For example you can define a concatenation using + for two strings, however the use of overrides can lead to confusing code if overused or used improperly.

What are namespaces?

Namespaces provide a method for explicitly defining scope to identifiers within it. They are defined using namespace identifier { named entities } They can be accessed by prefixing XXX :: or keyword using namespace XXX Namespaces should never be used in a headerfile

Can a class containing pure virtual (abstract) methods be instantiated?

No they serve as a base class for other methods. Derived classes are only instantiatable if all virtual methods are implemented.

When are objects destroyed?

Objects created on the stack are destroyed when the function they were created in return. For dynamically created objects, using new, delete is used. When the program terminates the heap is destroyed along with its objects

How do you build a C++ program?

On linux and most unix systems C++ programs are compiled using g++ and linked using ld. Sometimes c++ is used instead and ld is often hidden. e.g. >g++ h.cpp -o h >./h or g++ -c h.cpp g++ h.o -o h ./h Where h is a program in C++

Explain SOLID the design principles pneumonic

Single Responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Inversion

Modularization

Software is implemented as collection of independent units that communicate exchanging only critical data AKA LOW COUPLING Each unit performs a specialized function AKA HIGH COHESION

Example of release planning:

Stories (Name, Points): {(A,3), (B,5), (C, 5), (D,3), (E,1), (F,8), (G,5), (H,5), (I, 5), (J, 2)} Iterations (Seq, Story set, points): {(1, ABC, 13), (2, DEF, 12), (3, GHJ, 12), (4, I, 5)}

How does release planning work?

Stories are organized by priority in piles and are then iterated as releases. Factors in planning releases include desireablity to broadest user base, or to select, smaller higher base. Feasibility should also be considered.

Who writes the stories?

Stories are written by a customer team including developers, testers, product managers, actual users and customers. This prevents the stories from being too vague and business focused, or too technical so that everyone understands the goals.

Testable

Stories should be written to be testable. Passing a test proves the story has been successfully developed and completed. Tests should be automated where possible. Some stories cannot be tested.

Describe the structure of OOP

Structured around objects which are instances of classes Objects accept messages from other objects; messages call methods in the receiving object to perform actions (that is the programming logic of the invoked method) You may think of methods as procedures that are encapsulated inside a class e.g. Java, Objective-C, Swift, C#, and of course C++

What is meant by LISKOV SUBSTITUTION PRINCIPLE

Subtypes must be substitutable for their base types When you inherit from a base class, you must be able to substitute that base class without affecting program correctness or you aren't inheriting right. We should use inheritence when an object behaves like another not necessarily when it has an IS-A relationship

What does the function modifier constexpr do?

The compiler should evaluate the result at compile time

What does the function modifier inline do?

The compiler will try to embed the code for the function where it is called

What does the function modifier static do?

The function is not visible outside it's file/translation unit

Small

The stories should be small as possible without being too small.

Estimatable

The story must be estimatible, but developers may lack knowledge of either the technical details or of the story itself or the story may be too big. Stories that are too large are called epics

How do procedural languages work?

These process data according to internal programming logic, using basic statements or by calling other procedures, produce a result and return it to where they were called from main drives the program executing statements and procedure calls in sequence until completion e.g. Basic, Fortran, Pascal, C, GO, Python (sometimes)

What are default parameters?

They allow a function to be called without sending parameters. A default value is put into the parameter list of the function definition.

What is meant by negotiable?

They are not contracts, they are reminders to have a conversation.

How and why do we use include guards?

They are used to prevent multiple inclusion of the same headerfile. #ifndef MYHEADER_H #define MYHEADER_H #endif

Why use design patterns?

They encapsulate a particular design? Reuse previously demonstrated solutions Improve communications Think in design, not code Increase modularity, maintainability and evolution Encourages shared learning

What is the goal of listing acceptance tests?

They help the development team know when the story is complete. They are meant to be brief and may not need to be complete.

Why use C++

Third most popular programming language behind Java and C Balances OOP and power and speed of C Template library is good collection of starting points and add-on packages like boost Mastering C++ will improve your C, Java, C#

How is the cost of a particular story estimated?

This indicates the size and complexity, it is usually a relative to the other stories. A story should be an ideal evening of work for one developer.

How do OOP langauges provide functionality?

Through methods encapsulated in objects; also referred to as member functions

What are the goals of UML?

To enable modelling of OOD, visually depicting the high-level solution. To provide mechanisms to extend core concepts To be language independent. To support high-level collaborations, framework, patterns and components.

Describe the attributes and operations section of a UML diagram

Visibility: + public # protected - private Type Multiplicity Parameter List vis variable_name: type vis variable_name: type multiplicity = default_value {property} vis method_name (parameter_list): return_type {property}

Why use const?

We use const to preserve the value of a passed parameter.

What is meant by the design principal CODE TO AN INTERFACE, NOT AN IMPLEMENTATION?

When faced with a choice between interacting with subclasses or a supertype, choose a supertype This adds flexibility and simplifies architecture and reduces duplication

Are constructors and destructors inherited in inheritance?

Yes they are. Base class constructors are called first, base class destructors are called last. Unless otherwise specified the default constructor is called (no parameters)

Can a class in C++ be derived from more than one class?

Yes, this is called multiple inheritance.

How does array function in C++ differ from C

You can use new and delete to manage dynamically allocated arrays. Newer C++ standards allow initializer lists to dynamically allocate an array and initialize its contents.

How do you declare a constructor?

You declare a constructor just like a function, except it has the same name as the class and no return type. It is possible to use a variety of parameters or none.

Example of << operator overloaded to create a toString style method

friend ostream& operator<<(ostream& os, const Rectangle& rect); }; ostream& operator<<(ostream& os, const Rectangle& rect) { os << rect.width << "x" << rect.height; return os; }

Write the simplest C++ program

int main() { }

What are the three sections of a class diagram in UML?

name attributes operations

Access Specifiers

private: only visible within other members of same class public: visible anywhere the class and its instantiated objects are visible protected: protected members are accessible from other members of the same class and derived classes class default is private struct default is public


Related study sets

Financial Institutions Chapter 6

View Set

Medical Terminology - Musculoskeletal system

View Set

Vocabulary words for "Hottest, Coldest, Highest, Deepest"

View Set

‏القيم المدنية أساس دولة القانون (page 17 18)

View Set

Taking Proactive Steps to Succeed

View Set