Sei sulla pagina 1di 11

Welcome to Loginworks Softwares

HOW TO REUSE CODE IN OBJECT


ORIENTED PROGRAMMING
REUSE GOOD IDEAS
To save development time, code reuse is often
seen as a method of cutting project costs and
shortening time to market, but it has several
benefits of saving time.This study provides an
arguably much needed real, industrially-based
experiment regarding brainstorming. The results
and observations suggest that having a guided
approach to sourcing creative stimuli is very
beneficial. However, the Sweeper tool using
internally sourced stimuli provides a method that
is useful and more a practical alternative, as it is
based firmly in the domain of activity.For
information technology-intensive businesses the
code is expensive and time-consuming to
develop and code to reuse is considered a
fundamental productivity strategy.
TIPS ON WRITING REUSABLE CODE
1. KEEP THE CODE DRY. DRY MEANS “DON’T REPEAT YOURSELF
This is one of the main changes I have tried to bring in. Always try to
eradicate duplication and if you find any then move remove the duplication
to a relevant place. Sometimes this has to lead me to create Static Helper
classes or sometimes move it to the class it makes the most sense to have
it.
To save development time code reuse is often seen as a method of cutting
project costs and shortening time to market, but it has several benefits of
saving time.
2. MAKE A CLASS/METHOD DO JUST ONE THING:-
This is along the lines of the advice of giving the class only one reason to
change. This often means creating methods that other methods use but this
helps to make the methods/classes simple and less coupled.
3. WRITE UNIT TESTS FOR YOUR CLASSES AND MAKE IT EASY TO TEST
CLASSES:-

Writing code that is easy to test is decoupled. If you write code and are thinking about
writing a unit test for it then you tend to split up the code into smaller testable chunks.

4. REMOVE LOGIC OR MAIN CODE AWAY FROM ANY FRAMEWORK CODE:-

Following the rules above will help this.

5. TRY TO THINK MORE ABSTRACTLY AND USE INTERFACES AND ABSTRACT


CLASSES:-

Try to hide dependencies of code behind a more Generic interface/abstract class. The
benefit this gives the code is it creates a flexible point in the code where you can then hide
future changes behind.

6. CODE FOR AN EXTENSION.

This is particularly true with the above point. If you write code that uses interfaces then you
can extend that interface at a later point.
7. DON’T WRITE CODE THAT ISN’T NEEDED:-

Do the simplest thing possible. Don’t waste your time adding methods and classes that might be used
in the future. Keep the code simple and focused on what you are trying to deliver. I think I read/heard
Josh Bloch say once that “if in doubt, leave it out”. Basically, who wants to write code that no one
(including yourself) is going to use again.

8. TRY TO REDUCE COUPLING:-

When writing code thinks about the links and coupling the code is creating, does it need to be linked
to those other classes.

9. BE MORE MODULAR:-

OOP is the standard approach to software engineering. when solving a problem, must identify the
objects involved.

10. WRITE YOUR CODE IS AN EXTERNAL API:-

Imagine the code you are writing is a self-contained component.

It wasn’t going to be ten until I got to 8 and then thought no one writes 8 tips, let us add two more on.
It isn’t really a list but it’s sort of aims and mental notes I try to tell myself when writing code. They are
OOP AND CODE REDUSE
The Code Reuse Continuum
CODE REUSE
Code reuse is the use of existing software to deliver functionality. The following are common types of code reuse.

1.OFF THE SHELF

Using commercial or non-commercial products that exist as opposed to reinventing them.

2.EXTENSION

Extending your current systems, applications, services, and libraries as opposed to doing something completely
new.

3.COMPONENTS

Designing systems and applications to maximize reuse by dividing functionality into useful components that hide
complexity behind an interface.

4.LIBRARIES

Packages of reusable components designed to be reused.

5.SERVICES

Services reuse both the code and the operational aspects of a technology. For example, one team can operate a
market data service for a bank as opposed to having 50 systems and applications that connect to market data
feeds.
7.CUT & PASTE

It is common for developers to copy code with which they are familiar and change it to be something
new.

8.FORKING

Officially taking the code and changing it to be something new by creating a fork in a version control
system.

THE BENEFITS AND COSTS OF CODE REUSE

It allows multiple developers to integrate IP into their code using similar styles and programming
conventions.

This saves time, improves the features in your program, and generally makes for more cost-effective
programming.

Reusability is an important issue in software engineering for at least two major reasons.

The traditional approach tends to tread the mentioned “concepts” as “equal”, which creates some
illusions in those who did not grasp the main idea.

Forgot to address one thing. “Overriding” is really an OOP concept. So-called “overloading” is not. The
second concept does not deserve a separate name itself. This is one of the worst and confusing terms
Not using OOP using a pure OOP language may mean different approaches, but is possible
when one uses classes formally, not leveraging OOP power in any way. How? One can use
only static methods, never virtual ones, not even instance non-virtual methods (in some
languages, static methods can be abstract/virtual, quite naturally).

There is no any late binding and/or polymorphism without, say, encapsulation and
inheritance.

A compiler can distinguish them by profile inferred from the calling code.

Dont Use Generic Code Instead use small ,composable components.

Making Software to generic can make it too complicated to use.

CONCLUSION

Don’t give up on your efforts to write reusable code! This tip outlines three ways you can
modify your existing code to increase its reusability.

Connect with source url:-

https://www.loginworks.com/blogs/reuse-code-object-oriented-programming/
Thank You For Watching

Connect with This For More Inf^

https://www.loginworks.com

Call us: +1-434-608-0184

Potrebbero piacerti anche