0% found this document useful (0 votes)
10 views

L18Exercise-DesignPatternsWorkSheet

Uploaded by

hamzabjibji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

L18Exercise-DesignPatternsWorkSheet

Uploaded by

hamzabjibji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Name: ______________________________ Date: ______________________________

Software Engineering Specialization


Exercises: Design Patterns

Exercise 1: An object is loosely coupled if it is dependent on only a few other objects and/or the

dependencies are abstract. In the Observer design pattern, the subject may have
hundreds of observers (dependencies). In light of this, explain why the Observer
design pattern is said to be loosely coupled.

Exercise 2: Consider the code for the Singleton design pattern given below. Modify this code so
that at most 5 instances are created and each instance can be individually referenced.
Note that the keyword static indicates a class attribute/operation.

public class Singleton {


private static Singleton instance = null;

private Singleton() { }

public static Singleton getInstance() {


if (instance == null) {
instance = new Singleton();
}
return instance;
}
}

You might also like