Tuesday, January 27, 2015

" Dependency
injection is the way to decouple
conventional dependency relationships between objects. "

What is meant by
Dependency?

Suppose there are
two classes A and B. A can not carry out works without B and A can
not be reused without re using B. For this kind of scenario we said " A depends on B "

A – Dependant

B – Dependency

What Is meant byDecouple?

A and B classes are
decoupled if A can be use without B and and B can be used without A.

Lets assume creating a drawing application with Square , Triangle and Application classes. Square and Triangle class has same method name called draw() which draws square for a Square object and triangle for Triangle object.

Polymorphism to rescue !

The Greek meaning of the word "polymorphism" is "having different forms". Same object having different object behaviors !

Added interface called Shape and the common method draw() for both Triangle and Square. Square and Triangular classes implements Shape interface.

Shape triangular = new Triangular();

triangular.draw();

Shape square = new Square();

square.draw();

Lets Inject Dependencies !

Created a new class called DrawingTool and added a private member of Shape type (shape) and a setter for that. Created a method called drawShape(). Note that in DrawingTool class does not initiate any object. DrawingTool assumes that It will be provided a initiated object.

Advantage !

By using this method we can separate dependency from a whole class (DrawingTool)whichdoes not know what to draw. Lets say if we want to draw a triangle we don't have to modify the DrawingTool class. Only thing to do is pass a triangular to the setter.

Dependency to the triangle that the DrawingTool class has injected by the Application class. This is the way of injecting dependency.

Git is a popular version control system (VCS). Wait , what is a Version Control System ?

" Version Control System keeps track of the records changes to a set of files over time "

Why
we need Git or any other VCS ? Only to keep the code in a remote
repository as a backup ? Is VCS a waste of time ? Lets find answers for
these questions.

When we are creating individual projects we may not want to use a VCS. But VCS is very useful for team projects.

Imagine
you are working on a team project without using a VCS. Each of your
team members given individual tasks and plan is to combine those tasks
at the end. But practically it would be a very difficult. There can be
lots of redundant of codes, redundant of libraries, sometimes combining
costs lots of time and even may be unable to combine.

Imagine a scenario in which everybody can work under a same framework,
every one do there part and add to a common repository so that different
individuals can see who has committed (added the code), when it is
included, what are the changes etc. Life is so easy !

This is precisely what Version Control System capable for.

You always have a updated local repository (repository in your computer) of
the remote repository (repository in VCS network) (pull). Changes you've made is first effects in your local repository. Then push(add) those
changes to remote repository.

Basic git commands

git branch : show
which branch you are currently working

list down branches working on. start symbol shows the current branch working on