26.02.2015 Views

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The below two class diagrams will provide overview of what the actual difference is.<br />

First figure shows a sample implementation of Factory Patterns. In this figure there are<br />

two basic sections:-<br />

√<br />

√<br />

√<br />

√<br />

The actual product section i.e. Class “Product” it inherits from a abstract<br />

class “AbstractProduct”.<br />

The creational aspect section that’s “ConcreteCreator” class which inherits<br />

from class “Creator”.<br />

Now there are some rules the client who will need the “Product” object will<br />

have to follow. He will never refer directly to the actual “Product” object he<br />

will refer the “Product” object using “AbstractProduct”.<br />

Second client will never use “New” keyword to create the “Product” object<br />

but will use the “Creator” class which in turn will use the “ConcreteCreator”<br />

class to create the actual “Product” object.<br />

Figure: - 8.1 Class diagram of a factory Pattern<br />

So what are benefits from this architecture? All creational and initializing aspects are<br />

now detached from the actual client. As your creational aspect is now been handled in<br />

“ConcreteCreator” and the client has reference to only “Creator”, so any implementation<br />

change in “CreateProduct” will not affect the client code. In short now your creational<br />

aspect of object is completely encapsulated from the client’s logic.<br />

Now let’s look at the second class diagram which provides an overview of what actually<br />

“Abstract factory” pattern is. It creates objects for families of classes. In short it describes<br />

collection of factor methods from various different families. In short it groups related<br />

151

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!