Total Pageviews

Sunday, January 06, 2013

DIFFERENCE BETWEEN TOP-DOWN AND BOTTOM-UP APPROACH

TOP-DOWN APPROACH:

In Top-down approach, first, the main function is designed and progresses down towards the lowest level subsystems. When designing brand new system, Top-down approach is followed. Its advantage is that, it is easy to visualize, provide sense of completeness and easy to understand the progress at any stage.
Disadvantage includes, it may not help much in unit testing and there're chances of redundant business logics.

Here, an overview of the system is first formulated, specifying but not detailing any 1st level subsystems. Each subsystem is then redefined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements.

Procedural programming languages like C tend towards top-down as it is started with a function and adding up to it.


BOTTOM-UP APPROACH:

In Bottom-up approach, lowest level modules or subsystems are first developed and progresses upwards to the main function. It is used in Reverse Engineering process which requires analysing someone's design. Its advantage is strong business logic, ability to write good unit testing code and modifications can be performed easily. Its disadvantage is that it requires a lot of effort in writing test cases and programs can't be verified easily in the mid-stage.

Here, the individual base elements of the system are first specified in great detail. These elements are then linked to form larger subsystem.

OOP(Eg: C++, Java) tend to start from bottom, growing up, as it is begun with objects.


The reality is seldom one or the other approach but a combination of both.

Thanks for reading my blog... :-) Do comment about my blog... ;-)
WHAT DOES THE KEYWORD 'STATIC' MEAN???

In simple terms, a static variable/method can be accessed without the use of an object. There'll be only one copy of static variable/method for all the objects. This facility will be useful in several situations. For example, a static variable say count in library management program can count the no. of users visited on each day. 

POINTS TO BE REMEMBERED:


1) Whenever a class is loaded, its static statements are run first. 
EG:
class call
{
    int non_static=10;
    static int var3=5,var4;
    
    static    //STATIC BLOCK WILL RUN FIRST
    {
        System.out.println("Inside static block");
        var4=25;
        System.out.println("var3="+var3+"\t"+"var4="+var4);
    }
    
    void print()
    {
        System.out.println(non_static);
    }

    public static void main(String a[])
    {
        call obj=new call();
        obj.print();
    }
}

OUTPUT:
Inside static block
var3=5 var4=25
10


2)Only one copy of static variable/method will be available in a class, which all the objects use.


3)Static methods can call only other static methods.

4)Static methods must access only static data. This means that, nonstatic variables which are already declared outside the static method can't be accessed inside static method. But it is possible to declare nonstatic variable inside static methods and use it.

5)They can't refer to 'this' or 'super' keyword. (Since these keywords are related to objects).
EG:
public class Static 
{
    int non_static=10;
    static int var1=5,var2;
    
    void nonstatic_method()
    {
        System.out.println("this is nonstatic_method");
        System.out.println("var1="+var1);
        //in nonstatic methods, both static and nonstatic variables can be used.
    }
    
    static void static_method()
    {
        System.out.println("this is static_method");
        System.out.println("non_static variable="+non_static); 
        //ERROR! since this method is static, it can't use non static variables
        System.out.println("var1="+var1);
        System.out.println("var2="+var2);
        nonstatic_method();
        //This is again an error since static method can call only other static methods
    }
    
    public static void main(String a[])
    {
        Static obj=new Static();
        obj.nonstatic_method(); 
        //Object is mandatory to call nonstatic methods
        static_method();
        //static methods can be called without using object.
    }
}

OUTPUT:
this is nonstatic_method
var1=5
this is static_method
var1=5
var2=0


6)In the above example, static members are accessed from within the class in which they're declared. But when static members are to be accessed from another class, it must be done using the class name to specify which class' static member is accessed. For example, consider a class test which needs to access static variable var1 or static_method() of the previous eg.,

class test
{
    public static void main(String a[])
    {
        Static.var1=6;     //CLASS NAME IS MANDATORY HERE
        Static.static_method();
    }
}

OUTPUT:
this is static_method
var1=6
var2=0


7)And the last point is, note that we write as
      public static void main(String str[])
and not as 
      public void main(String str[])
The reason behind is that, main() function is the starting point of a program. In java, main() is a part of a class and hence an object is required to access it. But when the program starts, JVM needs to call main() for which objects are not available. This is the reason we add static which indicates that main() function can be called even without an object.

Thanks for reading my blog... :-) Hope it is useful... Put your response in the comment... ;-)