Thursday, December 17, 2015

What is interface in programming.



In real world, we see objects everywhere, and we interact with them by their interfaces.
For example: we start our computer by on/off button. Every computer has on/off button. User just find the on/off button and start it.  

Engineers make things, things has many complexities inside, engineers makes interface to simplify the complexities. So user can easily use those things.

Software engineers creates classes for objects, a class may have several methods, properties, events and other complexities. Software engineer provides an interface for this class, so the other software engineers can easily interact with this class by their interface.

Interface contains only signatures of methods, properties, events and indexers. Interface just a template, it does not contain definitions. Any class which implements the interface must implements the every method defined in the interface.

In real world almost every device has on/off button. So we design a simple interface for our device classes.

Interface contains only signature of methods.
Public interface IDevice{
            Public void toggleOnOff();
}

We have designed two different type of classes for our devices, both use same interface, both implements same methods but different definition as per device requirement.

Public class DesktopDevice:IDevice{
          Public void toggleOnOff(){
                        // just press the button.
                        // code.
              }
}

Public class SmartDevice:IDevice{
          Public void toggleOnOff(){
                        // press the button for 3 seconds
                        // code.
          }
} 

Usage for desktop devices.
IDevice dDevice = new DesktopDevice();
dDevice.toggleOnOff();

For Smart Devices.
IDevice sDevice = new SmartDevice();
sDevice.toggleOnOff();











Wednesday, December 9, 2015

Create custom filter in AngularJS.

AngularJS Filter is nothing but a function returns a function used as an expression by pipe sign "|"; 
AngularJS provides some built-in filters such as  
- currency
- lowercase
- orderBy

and many others but you can create your own, if you need!   
Filters are simply takes an input and parameters, you process it and return the output.

How do you create your own custom filter? 


Here is a simple example.   

//.js 

var app = angular.module("myApp",[]);
app.filter("truncateString",function( ){
        return function(input, limit){
          limit = parseInt(limit);
           return (input.length > limit)?input.substring(0,limit):input;
    }
}); 

// usage in html.  
<span ng-bind="data.description | truncateString:'30'">,</span>


- truncateString filter will define limit to the text by parameter. 


   

Monday, November 23, 2015

ng-model is not working in ng-include in AngularJs

i have split my layout and used ng-include and noticed that my scope is suddenly stop working in ng-include!, to overcome this problem i used $parent  like this. 

<input type=text ng-model="$parent.Contact.EmailAddress" />

It works great!

Find Volume

Volume is the amount of 3-dimensional space an object occupies.

             5in

   +--------+
  /        /|
 /        / |  5in
+--------+  |
|        |  |
|        |  +
|        | /
|        |/  5in 
+--------+



formula:
Length x Width x Height = Volume
5x5x5 = 125
Capacity of containing 125 object of cubic in. 

Tuesday, November 17, 2015

CSS background Stretch

Set the background-size property to the element. 
 
body {
    background-size: 100% auto; 

}