Designing a code can often take a lot of time, depending on the complexity of the coding. This is why code reusability has become a standard when it comes to computer programming. But to understand why you would reuse code, you need to understand what goes into creating code. This essay will compare and contrast procedural programming modules and objects. Also, it discuss the security terms in hiding code, passing of data versus data encapsulation, code reuse in more than one program, and how object-oriented methods are similar to procedural modules.
According to Gaddis (2010) there are two methods of programming that are primarily used: Object-oriented and Procedural. Procedural programming is more focused on creating procedures; object-oriented programming is focused on creating objects. When dealing with procedures, the data items are separate from the procedures. Gaddis (2010) says this can cause problems, but at the same time it will help the program become larger and more complex. But where procedural programming separates code and data, object-oriented programming handles it through encapsulation and data hiding.
Encapsulation takes an object and combines data and code into it. Data hiding makes it possible to hide code in the inside of an object from the code outside of the object. An object normally hides its data, but leaves the methods available for access. Gaddis (2010) states, “When an object’s internal data is hidden from outside code and access to that data is restricted to the object’s methods, the data is protected from accidental corruption.” There is also no reason to worry about formatting of the code inside the object, just the methods of the object.
The Essay on Java Programming: Mutator Method Assignment Q&A
On paper, write a method called sum with a while loop that adds up all numbers between two numbers a and b, inclusive, and returns the sum as its result. The values for a and b can be passed to the sum method as parameters. For instance: sum(1, 5) would return the value 15 (i.e., 1 + 2 + 3 + 4 + 5). What happens if the value of the second parameter is less than the value of the first? public int ...
If you want to reuse codes, the best way to do it is to create modules. They let you duplicate code in a program so that you can execute whenever you need the service. The Microsoft website (What Is Reusable Code?, 2013) says that code reusability can be used if the code doesn’t have to modified, and can perform a specific service regardless of what the application uses it. It just can be too complex of a code. Just as we use standards in everyday life, there are standard code that is used with computer programs. Venit and Drake say (2011) that inheritance goes along with code reusability. Inheritance takes the methods and attributes from old classes and uses them in new ones.
In conclusion, there are different aspects between object-oriented programming and procedural programming. These two methods have different ways of functioning within a program. And as long as a code isn’t to complex, code reuse is very possible.
References
Gaddis, T. (2010).
Starting Out with Programming Logic & Design (Second Edition ed.).
Addison-Wesley. Microsoft. (2013).
What Is Reusable Code? Retrieved from msdn.microsoft.com: http://msdn.microsoft.com/en-us/library/office/aa189112(v=office.10).aspx Venit, S., & Drake, E. (2011).
Prelude Programming Concepts and Design (Fifth Edition ed.).
Addison-Wesley.