Why Do We Need Singleton Pattern ? Answer
Why Do We Need Singleton Pattern ? Answer
Answer:
When the sole instance should be extensible by sub classing, and clients should
be able to use an extended instance without modifying their code.
In Factory pattern, we create object without exposing the creation logic to client
and the client use the same common interface to create new type of object.
The idea is to use a static member-function (static factory method) which creates
& returns instances, hiding the details of class modules from user.
Answer:
Answer: Implementing Singleton class with method name as that of class name
// Driver Code
class Main
{
public static void main(String args[])
{
// instantiating Singleton class with variable x
Singleton x = Singleton.Singleton();
Explanation: In the Singleton class, when we first time call Singleton() method, it
creates an object of class Singleton with name single_instance and return it to the
variable. Since single_instance is static, it is changed from null to some object. Next
time if we try to call Singleton() method, since single_instance is not null, it is returned to
the variable, instead of instantiating the Singleton class again.
Write simple java code for Factory with explanation?
Answer:
class Namer {
return first;
return last;
public FirstLast(String s) {
if (i > 0) {
last =s.substring(i+1).trim();
else {
last = s;
}}
class LastFirst extends Namer {
public LastFirst(String s) {
if (i > 0) {
else {
first = "";
class NameFactory {
int i = entry.indexOf(",");
if (i>0)
else
namer = nfactory.getNamer(entryField.getText());
txFirstName.setText(namer.getFirst());
txLastName.setText(namer.getLast());
Answer:
3. Describe Class Diagram Machine?
Answer: Class diagrams are the main building block in object-oriented modeling. They are
used to show the different objects in a system, their attributes, their operations and the
relationships among them.
In the example, a class called “loan account” is depicted. Classes in class diagrams are
represented by boxes that are partitioned into three:
The example shows how a class can encapsulate all the relevant data of a particular object in a
very systematic and clear way. A class diagram is a collection of classes similar to the one
above.
Answer: This sequence diagram tutorial is to help you understand sequence diagrams better;
to explain everything you need to know, from how to draw a sequence diagram to the common
mistakes you should avoid when drawing one.
There are 3 types of Interaction diagrams; Sequence diagrams, communication diagrams, and
timing diagrams.
Describe Behavioral State Diagram Machine?
Answer: A behavioral state machine diagram is a dynamic model that shows the
different states that a single class passes through during its life in response to events,
along with its responses and actions.
Typically, behavioral state machine diagrams are not used for all classes, but just to further
define complex classes to help simplify the design of algorithms for their methods
#4# What is temporal event? How many “Actors” can be in use case modeling?
Describe briefly.