cs504 Final Term Short Notes Subjective
cs504 Final Term Short Notes Subjective
Unified modeling UML provides two different mechanisms to document the dynamic behavior of the system.
language These are sequence diagrams which provide a time-based view and Collaboration Diagrams
which provide an organization-based view of the system’s dynamics.
2. Sequence diagram:A sequence diagram is a visual representation showing how objects interact
with each other in a specific order over time, illustrating the sequence of messages and events.
E.g:
The boxes denote objects (or classes), the solid lines depict messages being sent from one object to the
other in the direction of the arrow, and the dotted lines are called life-lines of objects.
Syntax: [instanceName][:className]
Name classes consistently with your class diagram (same classes).
Label objects in messages or when duplicates exist.
MCQs: The time required by the receiver object to process the message is denoted by an activation-
box.
Object Creation and Destruction: An object may create another object via a <create> message.
Similarly an object may destroy another object via a <destroy> message. An object may also
destroy itself. One should avoid modeling object destruction unless memory management is
critical. The following diagrams show object creation and destruction.
2. Collaboration diagrams:
Collaboration diagrams can also be used to depict the dynamic behavior of a system. They show
how objects interact with respect to organizational units. The sequence of messages determined
by numbering such as 1, 2, 3, 4,… This shows which operation calls which other
operation.Collaboration diagrams have basically two types of components: objects and
messages.Messages are numbered and can have loops.
3. Comparing sequence & collaboration diagrams:Sequence diagrams are best to see the flow of
time. On the other hand, static object connections are best represented by collaboration
diagrams. Sequence of messages is more difficult to understand in collaboration diagrams than
in the case of sequence diagrams. On the other hand, object organization with control flow is
best seen through collaboration diagrams. It may be noted that complex control is difficult to
express anyway but collaboration diagrams can become very complex very quickly.
4. Evaluating the Quality of an Object-Oriented Design:Only Reading
Judging the quality of a design is difficult. We can however look at certain object oriented design
attributes to estimate its quality.Consider a heat regulatory system for a room as shown below:
In this case, the room is not encapsulated as one entity and three different objects namely
Desired Temp, Actual Temp, and Occupancy maintain necessary information about a room.
If we encapsulate the three objects into one Room object as shown below, thenthe overall
coupling of the system will be reduced.
We can improve the situation even further by delegating this responsibility to the Room object
as shown below.
Suppose we have two functions defined for setting the desired temperature in the room:
SetMinimumValue(intaValue)
SetMaximimumValue(intaValue)
We can reduce the total number of messages in the protocol of this class by consolidation these
as shown below, hence reducing the overall complexity of the protocol.
SetLimits(intminValue, intmaxValue)
This model has been slightly modified by Clements et. al. and is shown in the following diagram:
Clement’s modified version of Krutchen’s 4+1 Architectural View Model. In this model, the
architecture is again prepared and analyzed from 5 different perspectives. The 4 main views are
Functional View, the Concurrency View, the Physical View, and the Development View. Code
view is not present in the original Krutchen model and is basically an extension of the
development view.
2. What Are Views Used For? Views are an engineering tool to help achieve desired system
qualities. Each view provides an engineering handle on certain quality attributes.
3. Hierarchical Views: Every view is potentially hierarchical, e.g. functional view could contain sub-
functions. Similarly development view contains directories which contain files. Code view would
have modules and systems that contain sub-modules and sub-systems respectively. Concurrency
view contains processes that are further subdivided into threads. Architectural views are related
to each other in complicated ways.
4. Architectural styles: The architectural model of a system may conform to a generic architectural
model or style.Each style describes a system category that encompasses:
A set of components (e.g., a database, computational modules) that perform a function
required by a system.
A set of connectors that enable “communication, coordination and cooperation” among
components.
Constraints that define how components can be integrated to form the system, and
semantic models that enable a designer to understand the overall properties of a
system by analyzing the known properties of its constituent parts
5. Layered Architecture: A layered architecture has many different layers. One typical example
of a layered architecture is an operating system where different layers are used to provide
services and functionality and the inner layers are closer to the machine hardware than the
outer layers. In this way, each layer isolates the outer layer from inner complexities. In order
to work properly, the outer layer only needs to know the interface provided by the inner
layer. If there are any changes in the inner layer, as long as the interface does not change,
the outer layer is not affected. This scheme tremendously portability of the system.
Lecture 26:
1. Design Patterns:
Christopher Alexander says, "Each pattern describes a problem which occurs over and over again in our
environment, and then describes the core of the solution to that problem, in such a way that you can
use this solution a million times over, without ever doing it the same way twice."
"Description of communicating objects and classes that are customized to solve a general design in a
particular context."
Name
Problem
Context
Forces
Solution
Resulting context
Rationale
Related patterns
Known uses
3. Classifications of deerns:
Creational patterns
Structural patterns
Behavioral patterns: Describe the patterns of communication between classes and objects
Participants
Singleton
3. Facade Pattern:
Intent
It provides a unified interface to a set of interfaces in a sub-system.
Façade defines a higher level interface that makes a subsystem easier to use
Applicability
You would use façade when you want to provide a simple interface to a complex sub-
system.
You would use façade pattern when there are many dependencies between clients and
the implementation classes of an abstraction.
You want to layer your subsystem.
Structure
Participants
Façade
Subsystem classes
E.g: totalSum = a + b + c +
d + e);
param3);
2. Include Files and Include Statements for Java and C++: Header files must include a construction
that prevents multiple inclusion. The convention is an all uppercase construction of the module
name, the file name and the h suffix. The construction is to avoid compilation errors.
3. Classes and Interfaces Class and Interface declarations should be organized in the following
manner:
Class/Interface documentation.
class or interface statement.
Class (static) variables in the order public, protected, package (no access modifier),
private.
Instance variables in the order public, protected, package (no access modifier), private.
Constructors.
Methods (no specific order).
4. Statements in Java and C++:
Type conversions must always be done explicitly. Never rely on implicit type conversion.
floatValue = (float) intValue; // NOT: floatValue = intValue;
Types that are local to one file only can be declared inside that file.
The parts of a class must be sorted public, protected and private.
5. Variables:
Variables should be initialized where they are declared and they should be declared in
the smallest scope possible.
Variables must never have dual meaning.
Class variables should never be declared public.
Related variables of the same type can be declared in a common statement. float x, y,z;
Variables should be kept alive for as short a time as possible.
Global variables should not be used. Variables should be declared only within scope of
their use.
Implicit test for 0 should not be used other than for boolean variables and pointers.
if (nLines != 0) // NOT: if (nLines) if (value)
6. Loop structures:
Only loop control statements must be included in the for() construction.
Loop variables should be initialized immediately before the loop.
The use of do .... while loops should be avoided.
The use of break and continue in loops should be avoided. These statements should only be
used if they prove to give higher readability.
The form for (;;) should be used for empty loops.
7. Conditionals:
Complex conditional expressions must be avoided.
The nominal case should be put in the if-part and the exception in the else-part of an if
statement.
The conditional should be put on a separate line.
Executable statements in conditionals must be avoided.
8. Miscellaneous:
The use of magic numbers in the code should be avoided. Numbers other than 0 and 1
should be considered declared as named constants instead.
Floating point constants should always be written with decimal point and at least one
decimal. double total = 0.0; // NOT: double total = 0;
Floating point constants should always be written with a digit before the decimal point.
double total = 0.5; // NOT: double total = .5;
Functions in C++ must always have the return value explicitly listed.
goto in C++ should not be used. Goto statements violates the idea of structured code.
Lec No. 30:
1. Comments: All comments should be written in English. In an international environment
English is the preferred language.Use // for all comments, including multi-line
comments.
2. Layout: Basic indentation should be 2.
for (i = 0; i < nElements; i++)
a[i] = 0;
3. Parenthesize to remove ambiguity: Parentheses should always be used as they reduce
complexity and clarify things by specifying grouping.
4. Breakup complex expressions: Complex expressions should be broken down into
multiple statements.
2. Magic Numbers:
Can you tell by reading the code what is meant by the numbers 20, 27, 3, 21, 22, and 23.
These are constant that mean something but they do not give any indication of their
importance or derivation, making the program hard to understand and modify. To a reader
they work like magic and hence are called magic numbers.
3. Use (or abuse) of Zero: The number 0 is the most abused symbol in programs written in C or
C++.
2. Guidelines: If the following guidelines are observed, one can avoid hazards caused by side
effects.
Never use “,” except for declaration
If you are initializing a variable at the time of declaration, do not declare another
variable in the same statement
Never use multiple assignments in the same statement
Be very careful when you use functions with side effects – functions that change the
values of the parameters.
Try to avoid functions that change the value of some parameters and return some value
at the same time
3. Performance: When a small set (a couple of functions) of functions which use each other is so
overwhelmingly the bottleneck, there are two alternatives:
Use a better algorithm
Rewrite the whole set
Bit fields are a convenient way to express many difficult operations. However, bit fields do
suffer from a lack of portability between platforms:
Does the function satisfy basic guarantee? Yes. Since the function does not create any objects,
in the presence of an exception, it does not leak any resources.
Does the function satisfy strong guarantee? No. The strong guarantee says that if the function
fails because of an exception, the program state must not be change. This function has two
distinct side-effects:
If: Second structural form is the If statement. In the following graph, the first node at the
left depicts the if statement and the two nodes next to the first node correspond to the
successful case (if condition is true) and unsuccessful case (if condition is false)
consecutively.
Case: In Case statement, control can take either of several branches (as opposed to only
two in If statement.) First node represents the switch statement (C/C++) and nodes in
middle correspond to all different cases.
While: A while loop structure consists of a loop guard instruction through which the
iteration in the loop is controlled. The control keeps iterating in the loop as long as the loop
guard condition is true.
Lec No. 39:
1. White box coverage schemes:
Statement Coverage: In this scheme, statements of the code are tested for a successful
test that checks all the statements lying on the path of a successful scenario.
Branch Coverage: In this scheme, all the possible branches of decision structures are
tested. Therefore, sequences of statements following a decision are tested.
Path Coverage: In path coverage, all possible paths of a program from input instruction to
the output instruction are tested.
Static analyzers: Static analyzers are software tools for source text processing. They parse the
program text and try to discover potentially erroneous conditions and bring these to the
attention of the verification and validation team. These tools are very effective as an aid to
inspections. But these are supplement to but not a replacement for inspections.
Checklist for static analysis: Tools that analyze
source code to
identify potential
errors, aiding
inspections but
notreplacingthem.
Symptoms