473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Code reuse

Hi all,

I'm hoping that some of you clever chaps could offer me some advice on code
reuse.

You see, whenever I make applications, I typically only find very limited
scope for code reuse. I also only find limited use for inheritance. For
example, the various types of users that my system might have to deal with.

I'm wondering if anyone could give me some tips on how to identify areas of
my design that could be reusable, where I can use inheritance and where to
use interfaces. I've read all the books that talk about why these things are
important but very few of them show you how to do it in the real world.

If anyone could point me to some online resources on this then that would be
great. I could also do with a couple of books on how to spot reusable
aspects of my designs and so on.

Any help would be great

Thanks all

Simon
Nov 18 '05 #1
3 1810
Simon,

normally it is not hard to see where the reuse is put.
It is not only in making a dll with common used methods or functionality,
but also the logical way of thinking in objects.

There are two kinds of reuse:
- Reuse within an application
- Reuse through several applications

Reuse within an application can be achieved by use of common methods and
behaviour in supperclasses,

Reuse through several applicatioons can be achieved by writing your code in
such a manner that it is application independant.

For instance, when you have three types of users in your system. Say:
- A Superuser
- A normal user
- A dummy user

they can be seen as three instances of the same user. Atributes makes the
difference between them. In this case you will have little reuse within the
application, because they all share the same class. But this class,
providing this behaviour, can be used within several applications.

In the case where the three users are defined as a subclass of user, all the
common functionality is put into class User (which is never to be
instanciated) while all the differences between the users are defined in the
subclasses : Super-user, normal user and dummy user. This can be seen as
reuse within an application. Again, this whole structure of user types can
be reused in almost every application you write.

The same is true for database access. If you write it once in a way that it
is not specific for a certain application, it can be reused over and over
again.

Another reuse is the use of design patterns. They are not really reuse of
code, but reuse of the way you approach problems which look very simular.

Greetz,
Ben

"Simon" <sh856531@microsofts_free_email_service.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi all,

I'm hoping that some of you clever chaps could offer me some advice on code reuse.

You see, whenever I make applications, I typically only find very limited
scope for code reuse. I also only find limited use for inheritance. For
example, the various types of users that my system might have to deal with.
I'm wondering if anyone could give me some tips on how to identify areas of my design that could be reusable, where I can use inheritance and where to
use interfaces. I've read all the books that talk about why these things are important but very few of them show you how to do it in the real world.

If anyone could point me to some online resources on this then that would be great. I could also do with a couple of books on how to spot reusable
aspects of my designs and so on.

Any help would be great

Thanks all

Simon

Nov 18 '05 #2
Why force code re-use? Start with design reuse, and code reuse will fall
out naturally.

"Simon" <sh856531@microsofts_free_email_service.com> wrote in message
news:#4**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I'm hoping that some of you clever chaps could offer me some advice on code reuse.

You see, whenever I make applications, I typically only find very limited
scope for code reuse. I also only find limited use for inheritance. For
example, the various types of users that my system might have to deal with.
I'm wondering if anyone could give me some tips on how to identify areas of my design that could be reusable, where I can use inheritance and where to
use interfaces. I've read all the books that talk about why these things are important but very few of them show you how to do it in the real world.

If anyone could point me to some online resources on this then that would be great. I could also do with a couple of books on how to spot reusable
aspects of my designs and so on.

Any help would be great

Thanks all

Simon

Nov 18 '05 #3
You asked specifically about 2 things: Inheritance and Interfaces. Let's
start with Inheritance, as that is the easiest to understand.

In Object-oriented programming, you have classes that encapsulate
functionality, rather than functions existing outside of any class. In
procedural programming, you have what is called function libraries, for
re-usable functions. Function libraries are DLLs, but they contain only
functions, not classes. In OOP, you have classes that encapsulate
functionality. For re-usability, you can use inheritance. For example, let's
talk about System.Web.UI.WebControl. All WebControls inherit this class.
Why? Because they all have some things in common. By creating a base class
that contains all the functionality that is shared by these classes, you
re-use the base class and its functionality in each derived class. For
example, all WebControls have an Attributes property, because all HTML
objects have attributes. By encapsulating this in a base class, you don't
need to re-write the code for each derived class, and if there is a need to
change this functionality, you change it in one place (the base class) and
all derived classes inherit that functionality.

Interfaces are a bit different. They define a "contract" if you will, that
specifies certain characteristics that are required by any class that
implements the Interface. These characteristics are either fields,
properties, or methods, which must have a certain signature. For example,
when creating a Server Control that implements IPostBackEventer, you must
implement a method called "RaisePostBackEvent." Why? Because, in order for
the class to handle PostBack events, it must have a method which can be
called from outside the class, which conforms to the signature of the
RaisePostBack method in the IPostBackEventHandler contract. In other words,
there is an external dependency in the architecture, which expects to find a
method with that signature.

Does that help?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Simon" <sh856531@microsofts_free_email_service.com> wrote in message
news:#4**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I'm hoping that some of you clever chaps could offer me some advice on code reuse.

You see, whenever I make applications, I typically only find very limited
scope for code reuse. I also only find limited use for inheritance. For
example, the various types of users that my system might have to deal with.
I'm wondering if anyone could give me some tips on how to identify areas of my design that could be reusable, where I can use inheritance and where to
use interfaces. I've read all the books that talk about why these things are important but very few of them show you how to do it in the real world.

If anyone could point me to some online resources on this then that would be great. I could also do with a couple of books on how to spot reusable
aspects of my designs and so on.

Any help would be great

Thanks all

Simon

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
3
by: DPfan | last post by:
What's exactly the meaning of "code reuse" in C++? Why such kind of reuse have more advantages over the counterpart in other language like in C? How is "code reuse" realized in C++? By...
6
by: patrick t music-images dt nl | last post by:
Hi, I'm evaluating Visual Studio and the .NET concept for his company, which is currently using Borland C++ Builder. Now I tried to create components/controls etc. in .NET and I can reuse it...
15
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here...
4
by: Simon | last post by:
Hi all, I'm hoping that some of you clever chaps could offer me some advice on code reuse. You see, whenever I make applications, I typically only find very limited
16
by: sailor.gu | last post by:
Hi all guys, As an embeded programmer with five year C experience, I did read many great books related with design, coding, test,debug,algorithms, compiler, design, os, pm and others. I...
6
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused...
2
by: Jeff Dege | last post by:
I'm working with a group that's been doing C++ coding for quite a long time, now, and in that environment we've pretty much worked out development practices that serve us well. We've been doing...
7
by: RichB | last post by:
I am just trying to get to grips with C# and OOP, and one of the benefits would seem to be code reuse. However I am not sure where to draw the line. I have the following section of code: if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.