Behavioural Design Patterns
Behavioral design patternsaredesign patternsthat identfy
common communicaton patterns between objects and realize
these patterns. By doing so, these patterns increase flexibility in
carrying out this communicaton
Strategy
Obs

The Command Pattern
The Command design pattern encapsulates commands (method
calls) in objects allowing us to issue requests without knowing the
requested operation or the requesting object. Command design
pattern provides the options to queue commands, u

Threads & multi-threading
Processes vs. Threads
A process is an executing instance of an
application.
A thread is a path of executionwithina
process.
A process can contain multiple threads.
Processes vs. Threads
Note that a thread can do anything a pr

The Singleton Pattern
Motivation
Sometimes it's important to have only one instance
for a class. For example, in a system there should be
only one window manager (or only a file system or
only a print spooler).
Usually singletons are used for centralize

Learning the Shell
Navigation
pwd (print working directory)
Used to find the name of the working directory
cd (change directory)
Used to change your working directory
To do this, type cd followed by the pathname of the desired working directory
Pathnames

The Template Method Pattern
Motivation
If we take a look at the dictionary definition of a template we can
see that a template is a present format, used as a starting point
for a particular application so that the format does not have to
be recreated eac

Chain of Responsibility Pattern
Motivation
The Chain of Responsibility design pattern allows an object to send a
command without knowing what object will receive and handle it.
The request is sent from one object to another making them parts of
a chain

The Visitor Pattern
Motivation
Visitor Pattern represent an operation to be performed on the
elements of an object structure.
Visitor lets you define a new operation without changing the classes
of the elements on which it operates.
The Problem:
Visitor

The Mediator Pattern
Motivation
In order to have a good object oriented design we have to create
lots of classes interacting one with each other.
If certain principles are not applied the final framework will end in
a total mess where each object relies

Design patterns
A design pattern is a description of the problem
and the essence of its solution.
It should be sufficiently abstract to be reused in
different settings.
Pattern descriptions usually make use of objectoriented characteristics such as inh

Islamic University of Gaza
Faculty of Information Technology
Operating Systems (CSCI 3306)
Programming Assignment #3: Matrix Product Using Threads
(Based on Operating System Concepts 7th ed.)
4.4
4.4

Factory Design Pattern
Saddam S. Zourob
The Factory Pattern
Factory: a class whose sole job is to easily
create and return instances of other classes
a creational pattern; makes it easier to
construct complex objects
instead of calling a constructor, u

Q1) The Collatz conjecture concerns what happens when we take any positive
integer n and apply the following algorithm:
n=
cfw_
n
,if nis even
2
3n+1, if n is odd
The conjecture states that when this algorithm is continually applied, all positive
integers

Memento pattern
problem: sometimes we want to hold onto a version of an important
object's state at a particular moment
memento: a saved "snapshot" of the state of an object or objects for
possible later use; useful for:
writing an Undo / Redo operatio

The Observer Pattern
Intent
Define a one-to-many dependency between objects so that when one
object changes state, all its dependents are notified and updated
automatically
Motivation
The need to maintain consistency between related objects without
maki

1. What the stages are of translate the java program from high level
source code to executed process.
2. Why the main method should declared as a static method?
3. (10 points)True/False? If False Why?, consider the
segments are in a correct program class

Correct the Code
/filename = persone.java
public class person cfw_
private:
int id;
String nm;
public:
int getId()cfw_ return id;
;
/filename = person2.java
private class person2 cfw_
public void main()cfw_
person ob;
System.out.printf(0, id);
System.out.

True-False
1. Classes and objects are really the same thing.
2. Actions and data that are grouped together are called objects.
3. The design of an object is called a class.
4. One class can create many objects.
5. A class is an instance of an object.
6. O

Review Questions
1. We use a stack to calculate postfix expressions. Below is an expression
consisting of 13 tokens. Show the contents of the stack after each token is
processed. Your answer should therefore consist of 13 pictures of the stack.
4 3 * 6 /

Presentation for use with the textbook Data Structures
and Algorithms in Java, 6th edition, by M. T. Goodrich, R.
Tamassia, and M. H. Goldwasser, Wiley, 2014
Queues
2014 Goodrich, Tamassia,
Goldwasser
Queues
1
The Queue ADT
The Queue ADT stores
arbitrary

Topological Sort
Introduction.
Definition of Topological Sort.
Topological Sort is Not Unique.
Topological Sort Algorithms.
An Example.
Implementation of Source Removal Algorithm.
Review Questions.
1
Introduction
There are many problems involving a set o

Presentation for use with the textbook Data Structures
and Algorithms in Java, 6th edition, by M. T. Goodrich, R.
Tamassia, and M. H. Goldwasser, Wiley, 2014
Doubly Linked Lists
2014 Goodrich, Tamassia,
Goldwasser
Doubly Linked Lists
1
Doubly Linked List

Presentation for use with the textbook Data Structures
and Algorithms in Java, 6th edition, by M. T. Goodrich, R.
Tamassia, and M. H. Goldwasser, Wiley, 2014
Stacks
2014 Goodrich, Tamassia,
Goldwasser
Stacks
1
Abstract Data Types (ADTs)
An abstract Examp

Shortest Path Algorithm
What is the Shortest Path Problem?
Is the shortest path problem well defined?
The Dijkstra's Algorithm for Shortest Path Problem.
Implementation Dijkstra's Algorithm
What is the shortest path problem?
In an edge-weighted graph,

Binary Heaps
What is a Binary Heap?
Array representation of a Binary Heap
MinHeap implementation
Operations on Binary Heaps:
enqueue
dequeue
deleting an arbitrary key
changing the priority of a key
Building a binary heap
top down approach
bottom up

Binary Search Trees (BST)
What is a Binary search tree?
Why Binary search trees?
Binary search tree implementation
Insertion in a BST
Deletion from a BST
Binary Tree Traversal
1
Binary Search Trees (Definition)
A binary search tree (BST) is a binary

The Design and Analysis of Algorithms
Chapter 11:
Limitations of
Algorithmic Power
P, NP and harder
problems
Limitations of Algorithmic
Power
Introduction
Lower
Bounds
P, NP, NP-complete and NP-hard
Problems
2
Introduction
Algorithm efficiency:
Logarit

The Design and Analysis of Algorithms
Chapter 10:
Iterative
Improvement
Simplex Method
Iterative Improvement
Introduction
Linear Programming
The Simplex Method
Standard Form of LP Problem
Basic Feasible Solutions
Outline of the Simplex Method
Example
Note

The Design and Analysis of Algorithms
Chapter 6:
Transform and
Conquer
Genetic Algorithms
Genetic Algorithms
What is a GA
Terms and Definitions
Basic Genetic Algorithm
Example
Selection Methods
Crossover Methods
Mutation
2
What is a GA
Searches for good s

The Design and Analysis of Algorithms
Chapter 2:
Fundamentals of the
Analysis of Algorithm
Efficiency
Mathematical Analysis of Non-recursive and
Recursive Algorithms
Section 2.3. Mathematical
Analysis of Non-recursive
Algorithms
Steps in mathematical anal

The Design and Analysis of Algorithms
Chapter 6:
Transform and
Conquer
Shell Sort
Shell Sort
Improves on insertion sort
Compares elements far apart, then
less far apart, finally compares
adjacent elements
(as an insertion sort).
2
Idea
arrange the data se

The Design and Analysis of Algorithms
Chapter 6:
Transform and
Conquer
Chapter 6.
Transform and Conquer
Algorithms
Basic Idea
Instance simplification
Presorting
Search with presorting
Element uniqueness with presorting
Gaussian elimination
Representat

The Design and Analysis of Algorithms
Chapter 9:
Huffman Codes
Huffman Codes
Basic Idea
Building the tree
Implementation
Encoding
and Decoding
Analysis
Discussion
2
Basic Idea
Fixed-length encoding
ASCII, Unicode
Variable-length encoding : assign
longer