U can Register and EARN MONEY

Interview qustion in IT field_NET Architecture

.NET Architecture
(B) What are design patterns ?
Design patterns are recurring solution to recurring problems in software architecture.

(A) Can you list down all patterns and there classification ?
There are three basic classification of patterns Creational, Structural and Behavioral patterns.
Creational Patterns
√ Abstract Factory:- Creates an instance of several families of classes
√ Builder :- Separates object construction from its representation
√ Factory Method:- Creates an instance of several derived classes
√ Prototype:- A fully initialized instance to be copied or cloned
√ Singleton:- A class of which only a single instance can exist
Structural Patterns
√ Adapter:-Match interfaces of different classes.
√ Bridge:-Separates an object’s interface from its implementation.
√ Composite:-A tree structure of simple and composite objects.
√ Decorator :-Add responsibilities to objects dynamically.
√ Façade:-A single class that represents an entire subsystem.
√ Flyweight:-A fine-grained instance used for efficient sharing.
√ Proxy:-An object representing another object.
Behavioral Patterns
√ Mediator:-Defines simplified communication between classes.
√ Memento:-Capture and restore an object's internal state.
√ Interpreter:-A way to include language elements in a program.
√ Iterator:-Sequentially access the elements of a collection.
√ Chain of Resp:-A way of passing a request between a chain of objects.
√ Command:-Encapsulate a command request as an object.
√ State:-Alter an object's behavior when its state changes.
√ Strategy:-Encapsulates an algorithm inside a class.
√ Observer:-A way of notifying change to a number of classes.
√ Template Method:-Defer the exact steps of an algorithm to a subclass.
√ Visitor:-Defines a new operation to a class without change.

(A)What’s difference between Factory and Abstract Factory Pattern’s?
First read the definition provided in the first question about both these patterns. The common thing they have is that they belong to creational patterns. In short they hide the complexity of creating objects.

The main difference between factory and Abstract factory is factory method uses inheritance to decide which object has to be instantiated. While abstract factory uses delegation to decide instantiation of object. We can say Abstract factory uses factory method to complete the architecture. Abstract Factory is one level higher in abstraction over Factory.

The below two class diagrams will provide overview of what the actual difference is. First figure shows a sample implementation of Factory Patterns. In this figure there are two basic sections:-

√ The actual product section i.e. Class “Product” it inherits from a abstract class “AbstractProduct”.
√ The creational aspect section that’s “ConcreteCreator” class which inherits from class “Creator”.
√ Now there are some rules the client who will need the “Product” object will have to follow. He will never refer directly to the actual “Product” object he will refer the “Product” object using “AbstractProduct”.
√ Second client will never use “New” keyword to create the “Product” object but will use the “Creator” class which in turn will use the “ConcreteCreator” class to create the actual “Product” object.

So what are benefits from this architecture? All creational and initializing aspects are now detached from the actual client. As your creational aspect is now been handled in “ConcreteCreator” and the client has reference to only “Creator”, so any implementation change in “CreateProduct” will not affect the client code. In short now your creational aspect of object is completely encapsulated from the client’s logic.
Now let’s look at the second class diagram which provides an overview of what actually “Abstract factory” pattern is. It creates objects for families of classes. In short it describes collection of factor methods from various different families. In short it groups related factory methods. Example in this the class “Creator” is implemented using the “Abstract” factory pattern. It now creates objects from multiple families rather one product.
(I)What’s MVC pattern?
Twist: - How can you implement MVC pattern in ASP.NET?
The main purpose using MVC pattern is to decouple the GUI from the Data. It also gives the ability to provide multiple views for the same Data. MVC pattern separates objects in to three important sections:-

√ Model: - This section is specially for maintaining data. It is actually where your business logic, querying database, database connection etc. is actually implemented.
√ Views: - Displaying all or some portion of data, or probably different view of data. View is responsible for look and feel, Sorting, formatting etc.
√ Controller: - They are event handling section which affects either the model or the view. Controller responds to the mouse or keyboard input to command model and view to change. Controllers are associated with views. User interaction triggers the events to change the model, which in turn calls some methods of model to update its state to notify other registered views to refresh their display.
Ok now this was all in theory. Let’s look at how in actually ASP.NET can we implement MVC pattern. During interview with theory they will be looking at more have you really implemented MVC or its just talks. Following are the various sections of ASP.NET which maps to MVC sections:-

√ Model: - This section is represented by Data view, Dataset, Typed Dataset,
Business components, business entity models etc. Now this section can then be tied up to either windows application or web UI.
√ View: - ASPX, ASCX, or windows application UI like data grid etc. form the view part of it.
√ Controller: - In ASP.NET the behind code is the controller. As the events are handled by that part. Controller communicates both with Model as well as
view.

(A)How can we implement singleton pattern in .NET?
Singleton pattern mainly focuses on having one and only one instance of the object running. Example a windows directory service which has multiple entries but you can only have single instance of it through out the network.

Following are the three steps needed to implement singleton pattern in .NET:-
√ First create your class with static members.
Public class ClsStaticClass
Private shared objCustomer as clsCustomer
End class
This ensures that there is actually only one Customer object through out the project.
√ Second define a private constructor to your class.
Note: - defining a private constructor to class does not allow a client to create objects directly.
√ Finally provide a static method to get access to your singleton object.

(A)How do you implement prototype pattern in .NET?
Twist: - How to implement cloning in .NET ? , What is shallow copy and deep copy ?
Cloning is achieved by using ICloneable of the System namespace. It has a “Clone” method which actually returns the reference of the same copy. Clone method allows a Shallow copy and not a deep copy. In Shallow copy if you make changes to the cloned object it actually does change on the main object itself. So how is deep copy achieved, by using “ISerializable” interface? So what you do is first serialize the object then deserialize back to a complete new copy. Now any changes to this new copy do not reflect on the original copy of the object, this is called as Deep copy.

(I)What are the situations you will use a Web Service and Remoting in projects?
Well “Web services” uses “remoting” concepts internally. But the major difference between “web service” and “remoting” is that “web service” can be consumed by clients who are not .NET platform. While remoting you need the client to be .NET compliant. Regarding the speed issue “Remoting” is faster than “Web Services”. So I think when deciding the architecture side of choosing between “Web services” and “Remoting” keep the cross platform issue and the speed issue in mind.

(I) How can we implement observer pattern in .NET?
Observer patterns can be implemented using “Delegates” and “Events”. I leave this to the readers to implement one sample code for observer patterns.

(B)What is three tier architecture?
The three tier software architecture emerged in the 1990s to overcome the limitations of the two tier architecture. There are three layers in when we talk about three tier architecture:-
User Interface (Client) :- This is mostly the windows user interface or the Web interface. But this has only the UI part.
Mid layer: - Middle tier provides process management where business logic and rules are executed and can accommodate hundreds of users (as compared to only 100 users with the two tier architecture) by providing functions such as queuing, application execution, and database staging.
Data Access Layer: - This is also called by the famous acronym "DAL" component. It has mainly the SQL statement which do the database operation part of the job.
The three tier architecture is used when an effective distributed client/server design is needed that provides (when compared to the two tier) increased performance, flexibility, maintainability, reusability, and scalability, while hiding the complexity of distributed processing from the user.
(I)What are different ways you can pass data between tiers?
There are many ways you can pass data between tiers :-
√ Dataset the most preferred one as they maintain data in XML format.
√ Datareader
√ Custom classes.
√ XML