Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Maximize your code reusability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Maximize your code reusability " Watch "Maximize your code reusability " New topic
Author

Maximize your code reusability

John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Hi:
can any one give some tips on how to maximize your code reusability?
Thanks,
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The short answer has since the 1970s been high cohesion, low coupling. Easier said than done. How do you create goodness? How do you measure success?
Looking for those answers, I recently stumbled across a Great Little Paper by Robert Martin that explains Open for extensibility, Closed for modification as well as I've ever seen, and adds a graph of abstractness vs stability. Things built on the "main line" contribute to reusability; others are potential problems. See if "Uncle Bob's" ideas help.
BTW: Back when I was a "seeker" (knows there is a problem, has no clue what the solution is) my own measure of success for reusability was: How complex are the instructions? The ideal is "Call this, it will give you an answer." The reality was more like "set up five files, call three programs in sequence, wave a dead chicken over the keyboard, call five methods in sequence ..." I guess I still use this measure - if I look at the docs for something and don't get it in a couple minutes, I move on.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Moving to OO and Patterns because Junilu is MAKING me
< topic swiper!! >


"JavaRanch, where the deer and the Certified play" - David O'Meara
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Don Liu:
can any one give some tips on how to maximize your code reusability?

Here are some thoughts:
- write unit tests for your code, preferably first. By writing unit tests for your classes, they already are used by at least two clients - the tests and the production code. Writing tests for your code will therefore help you to make your code easier to use in different places.
- write small methods/classes. The more focused your units are, the more likely they can be reused in a different context.
- don't tolerate duplication. If you have two snippets of code which are similar in structure and/or behaviour, you have missed an opportunity to reuse. By refactoring the commonality in its own place, you often get more general pieces of functionality which later can get reused in other places.
Did that help?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Thanks a lot! Ilja and Stan. It really helps.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
Looking for those answers, I recently stumbled across a Great Little Paper by Robert Martin that explains Open for extensibility, Closed for modification as well as I've ever seen, and adds a graph of abstractness vs stability. Things built on the "main line" contribute to reusability; others are potential problems. See if "Uncle Bob's" ideas help.

And if it does help, you might want to consider the book "Agile Software Develoment - Principles, Patterns and Practices" by the same author.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maximize your code reusability
 
Similar Threads
Multiple Inheritance - Reusability
reusability
Abstract classes and Interfaces in Project
JFrame Maximize button
JDialog