Final Flashcards
Cyclomatic Complexity
Software metric used to measure complexity of a program
Asymptotic Analysis
1 - Find the largest element in an ordered list
Log(N) - we can discard some portion of the space repeatedly, ex: binary search
N - process each element some constant number of times (ex: find the largest number in an unordered list
N Log(N) - break the problem up into sub problems and recombine the solution, ex: sorting
N^2 - naive implementation to find the closest set of points in an unordered list
2^N - try every single combination and see if it is right
NP problem
a problem for which it’s quick to check if an answer is correct.
NP-hard problem
a problem such that, if you have a strategy to solve it, you can quickly apply that strategy to any problem in NP.
NP-complete problem
a problem that is both NP and NP-hard.
Design pattern
proven solution to a recurrent problem in a context
Why study design patterns?
-Reuse existing, high quality solutions to commonly recurring problems
-Establish common terminology to improve communications within teams
-Improve modifiability and maintainability of code
-Adoption of improved object oriented design strategies
OO Design Principles
Encapsulation
Information Hiding
Object Reuse
OO Design Principles - Encapsulation
-Bundling of data with operations that operate on that data.
-It’s a language facility / construct.
-It’s not specific to just OO programming.
OO Design Principles - Information Hiding
-Strives to shielf client modules from the internal works of a module.
-Creator stressed hiding “difficult design decisions or design decisions which are likely to change”
-Encapsulation facilitates but does not guarantee information hiding
Rules: don’t expose data, don’t expose the diff between stored and derived data (ex: use an accessor method named speed() or getspeed() rather than calculateSpeed() to return an attribute called speed of an object
Don’t expose a class’ internal structure or implementation details of a class
OO Design Principles - Object Reuse
Class inheritance-reuse by sub-classing/extending/inheriting. Often referred to as white-box reuse
Object composition-new functionality is obtained by creating an object composed of other objects, black-box reuse
The generalization class (superclass) explicitly captures the common attributes and methods
The specialization class (subclass) extends the implementation with additional attributes and methods
Disadvantages of Reuse with Inheritance
-Breaks encapsulation since it exposes a subclass to implementation details of its superclass
-“Whte-box reuse” since internal details of superclasses are often visible to subclasses
-Subclasses may have to be changed if the implementation of the superclass changes
Reuse with Composition
**re-do thie one closer to final
New functionality is obtained by delegating functionality to one of the objects being composed
Object composition is defined dynamically at run time through objects acquiring references to other objects
Design - Module Cohesion
Degree of relatedness/similarity between elements within a module. It is an intra-module measure.
Levels of Cohesion:
Functional: the perform a single specific funtion
Clustered, Sequential, Communicational, Procedural, Temporal, Logical, Coincidental.
Modules with high cohesion tend to be more maintanable and reusable.
Design - Module Coupling
degree of dependence between two or more modules.
Types:
Data: all communications between modules is through data element arguments
Stamp: communication includes a data structure arguments (some fields are not needed)
Control: an argument from a module can control the flow of the other for example a flag
External: they reference an externally declared data element
Common: they reference an externally declared data structure
Content: one references the contents of the other