سؤال

I don't quite get the concept of software reuse ... Wikipedia provided "code reuse" & "re-usability" nothing specific about SOFTWARE reuse ... Please, if you could explain the concept clearly, I'd be grateful.

هل كانت مفيدة؟

المحلول

The name is self-explanatory. There is some software that you want to reuse. It is quite simple to understand.

I will use Java to explain reusability so please bear with me.

class Parent{
    int[] numbers;
    public void supplyNumbers(int[] someNumbers){
        this.numbers = someNumbers;
    }

    public void performSorting(){
        for(int i=0;i<numbers.length;i++){
            //perform sorting here
        }
    }
}  

So there is a class Parent that has an array of numbers and two methods to supply the numbers and perform some sorting operation on it.
Now, I want to create another class that needs similar such functions. Instead of re-writing the code, all I would do is I would inherit the code as follows:

class Child extends Parent{

}  

So where is the code ? Well, I do not need to write anything as it will be automatically provided to me as I have inherited it from the Parent class.
I am reusing what I wrote previously. This is code reusability.

Also, when you make imports in Java, you are reusing the code the devs wrote. :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top