 |
What are the relationships for UML Class diagram?
|
| |
| Relationships |
Notations |
Descriptions |
| Association |
 |
An Association is a generic relationship between two classes. This relationship
is indicated by a line connecting the two classes. |
| Composition |
 |
A Class must be a member of another class. This relationship is indicated by a
line with a filled diamond.
|
| Dependency |
 |
When a class uses another class, perhaps as a parameter and so depends on that
class. This relationship is indicated by a dotted arrow.
|
| Aggregation |
 |
Aggregation indicates a whole part or "has-a" relationship. This relationship
is indicated by a line with a hollow diamond
|
| Generalization |
 |
It is the equivalent of an Inheritance or "is-a" relationship. This
relationship is indicated by an arrow with a hollow arrowhead pointing to the
base class.
|
|
 |
What are usecase Diagrams?
|
| |
Usecase diagrams identify the functionality provided by the
system(usecases) , the users who interact with the system(actors) and the
association between the users and the functionality.
Example
|
 |
What are Class diagrams?
|
| |
Classes are building blocks in Object Oriented Programming. A
Class diagram is depicted using a rectangle divided in to three sections.
Example
|
 |
What are the relationships for UML Sequence diagram?
|
| |
| Relationships |
Notations |
Descriptions |
| Object |
 |
Objects are instances of classes, and are arranged horizontally. The pictorial
representation for an Object is a class (a rectangle) with the name prefixed by
the object name (optional) and a semi-colon. |
| Actor |
 |
Actors can also communicate with objects, so they too can be listed as a
column. An Actor is modeled using the ubiquitous symbol, the stick figure.
|
| Lifeline |
 |
The LifeLine identifies the existence of the object over time. The notation for
a Lifeline is a vertical dotted line extending from an object.
|
| Activation |
 |
Activations, modeled as rectangular boxes on the lifeline, indicate when the
object is performing an action.
|
| Message |
 |
Messages, modeled as horizontal arrows between Activations, indicate the
communications between objects.
|
|
 |
What is Facade pattern?
|
| |
Facade pattern sits on top of lot of subsystems and makes access easy to interfaces of these subsystems
|
 |
What is Observer pattern?
|
| |
Observer pattern can be implemented using "Delegates" and "Events".
The Observer pattern is a way for an object to notify all of it’s dependants when something changes based on a one to many relationship
|
 |
How can we implement singleton pattern in .NET?
|
| |
Singleton pattern manily focuses on having one and only instance of the object running.
Following are the three steps needed to implement singleton pattern in .NET
1.First Create your class with static members
class LoadBalancer
{
private static LoadBalancer instance;
}
This ensures that there is actually only one LoadBalancer object through out the project.
2.Second define a private constructor to your class.
private LoadBalancer()
3.Provide a static method to get access to your singleton object.
public static LoadBalancer GetLoadBalancer()
{
}
|
 |
How to implement Thread safe single pattern .NET?
|
| |
Using Static Initialization Approach we can acheive thread safe
public sealed class Singleton
{
private static readonly Singleton _instance = new Singleton();
private Singleton(){}
public static Singleton Instance
{
get
{
return _instance;
}
}
}
-It has a static readonly member. In the example above, the member called _instance is a static
instance of the Singleton class. This means it only can be created once by the runtime.
Static members only exist in one place. We use this static reference to an actual, regular object.
-It has an Instance property. The Instance static property allows easy access to the singleton.
This is a public property and is also called a getter.
-It has a private constructor. Having a private constructor means that a class cannot be created
anywhere but inside its own methods. So it must be accessed through the singleton reference.
Finally, it uses the sealed keyword decoration to improve some optimization options.
|
 |
What is a design pattern?
|
| |
A design pattern is a proven design solution to a common problem faced by software developers. Design patterns became popular with the rise of object oriented analysis and design (OOAD).
Design patterns are designed to help developers deliver higher quality, more easily maintained software products in less time and at lower cost.
Design patterns are:
encapsulated - They embody design knowledge regarding collaboration of classes and objects, distribution of responsibility, and other design issues.
object-oriented - They incorporate OOAD principles—e.g., low coupling, high cohesion.
reusable - They are adaptable, flexible, general solutions to classes of problems with broad applicability. Design patterns simplify the task facing the developer.
Which are the three main
categories of design patterns?
There are three basic classifications 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 in which only a
single instance can exist
Note:
- The best way
to remember Creational pattern is by ABFPS (Abraham Became First President of
States).
Structural Patterns
·
Adapter:-Match interfaces of
different classes.
·
Bridge:-Separates an object’s
abstraction 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.
Note :
To remember
structural pattern best is (ABCDFFP)
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.
|
 |
What is the difference between Composition and Aggregation?
|
| |
Composition: When you "destroy" the whole, the parts are also destroyed.
Aggregation: When you "destroy" the whole, the parts can still continue to exist.
Composition real world example:
hotel with rooms. The hotel is composed of rooms, as they won't exist without the hotel.
Aggregation real world example:
A pretty clear (and classic) example of "aggregation" is a course with
students. You can say that the course "aggregates" its students, but when
you delete the course from the system (e.g. it's finished), the students
themselves remain, e.g. as students in other courses.
|