You are on page 1of 2

Assignment # 4

Question # 1
You are given some literals (variable names, data type names, function names) in Column1. Rewrite them in column-3 by following the standard C++ / JAVA coding conventions. Note: Column-2 contains description of each literal (given in column-1) for your help.

Column-1 (Literals)

Column-2 (Description)

Column-3 (Re-Written after following standard JAVA coding conventions) ComplexNumber

complexnumber

monthlytaxrate

speed_of_light

void setstudentgrade() { } address

complexnumber is a data type. Any variable of this type can be used to store a complex number. monthlytaxrate is a variable used to store an employees monthly tax rate. speed_of_light is a constant variable to store the speed of light. setstudentgrade() is function in student class. address is a private member of Employee class

MonthlyTaxRate

SPEED_OF_LIGHT void setStudentGrade(){ } Employee { Private char address_; }

Question # 2
"Suppose you want to develop a Graphics library, you want that the client should be able to instantiate only one instance of the library class(s) at a time" What design pattern you think, is most appropriate for implementing such type of library? Answer your question with solid reasons.

Answer :
Singleton Pattern is most appropriate implementin such type of library. Singleton Patternprovide a single point of access to a particular instance ,and a single point of nstance.

Reasons:
1) The singleton pattern is one of the GOF (Gang of Four) patterns. This particular pattern provides a method for limiting the number of instances of an object to just one. Its an easy pattern to grasp once you get past the strange syntax used. 2) It provides this facility of instantiation for a single instace.

3) The intent of this pattern is that a class only has one instance and provides a global point of access to it. 4) The singleton can implement interfaces and inherit from other classes.

5) Singletons do not create unnatural interdependencies made by passing a context object around, where every piece of code will bind to everything in the context object. 6) 7) The power of the Singleton goes beyond just controlling the instance count. Singletons offer an actual object .

You might also like