Wednesday, January 28, 2015

AngularJS for very Beginners

"AngularJS" also referred to as "Angular" is an open source structural framework for dynamic web apps.

AngularJS is created by Google and the community of individual developers. AngularJS is a MVC based framework which reduces much of the code by using dependency injection and data binding. 

To use Angular you need to download its framework from here. Get the stable and minified version of the framework. This will be the reference for the script we are going to create.

1.    <html ng-app>


2.    <script src="angular.min.js"></script>

3.    Text : <input ng-model="textName">
4.    <br/>


5.    {{textName}}
 


6.    </html>

Explanation of the code

1.   "ng-app": saying html to use angular

2.   set reference for the script (angular.min.js is included in same folder of test.html)

3.   "ng-model": Model to the input

4.   "{{textName}}": View of the input 

Output 

 









We looked at Model and View architecture, Lets look at Controller in action !

1.   <html ng-app>
2.   <script src="angular.min.js"></script>

3.   <button ng-click="num=num+1" ng-init="num=0">Add One</button>

4.   Number: {{num}}
5.   </html>

Explanation of the code

3.   "ng-click": click handler for Angular   ::  "ng-init": initial value of num

Output 










Tuesday, January 27, 2015

What is Dependency Injection & Polymorphism


" 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 by Decouple ?

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) which does 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.

Basic git commands for beginners with examples


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




git status : current status of your local repository (modified files)




modified file with the path is shown red color




git diff path-to-file : show what are the changes of modified file




removed line of the file is shown with red color




git reset --hard HEAD : reset local repository


HEAD is now reset to current fix AAERESAA-19915



less .git/config : configure git configurations


git pull : update local repository from remote repository (pull changes from  remote repository to local)


git checkout – –track path-to-branch : changes the working path


git reset – –soft shaID : reset the state until given shaID


git add path-to-file : stage the file (ready the file to commit)


git commit -m “commit-message” : commit the file


git push origin branch-name : push to remote repository


gitk : shows the git repository browser