Refactoring Process

Posted on 2005-03-01
Medium Priority
Last Modified: 2008-02-26
What is the the refactoring process? I keep hearing about it but im not sure what it is all about. Also I have found that there are a few concepts such as responsibility-driven, coupling, cohesion. Should I be worried about violating them?
Question by:eli290
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 37

Expert Comment

ID: 13432666
LVL 86

Expert Comment

ID: 13432683
Refactoring is basically redesigning code in a more rational manner. 'Responsibility' is about what 'duties' a class is intended to perform and it's functional boundaries relative to other classes. 'Coupling' is the notion of how much a class should be dependent on another or others. 'Cohesion' seems quite general but is probably centred around how things 'hang together'. These are all factors to be tken into account in good design or refactoring.
LVL 37

Accepted Solution

zzynx earned 2000 total points
ID: 13432708
Instead of writing new applications from scratch, much of a developer's job today involves changing existing code.
Simple changes may consist of just adding on to the existing code.
However, as multiple revisions or extensive changes are made, the internal structure of the software may begin to deteriorate.
It can become difficult to understand, and expensive to modify and maintain. That is why it is important to know how to refactor code.
Refactoring is changing the internal structure of software to make that software easier to understand and cheaper to modify
without changing its observable behavior.
LVL 19

Expert Comment

by:Jim Cakalic
ID: 13434002
Umm, yes. You should be worrying about violating them.

There are numerous design principles and heuristics which we should use as guidance in producing good OO designs. Coupling and cohesion are two measurements (or metrics) we can use to help us evaluate how well (or how poorly) we've applied these principles. And where we have low cohesion and/or high coupling, we have the opportunity to refactor our design to improve cohesion and/or reduce coupling.

Robert Martin of Object Mentor has written extensively about OO design principles. You can read some of his work for free at http://www.objectmentor.com/resources/listArticles?key=topic&topic=Design%20Principles. I'd start with the Principles and Patterns piece and then dive into the others as you might want more depth. He elaborates on these principles as well as patterns and the software development process in his book Agile Software Development. I'd recommend it more heartily but my respnosibilities have prevented me from doing much more than skimming.

Another author that I would advocate is Arthur Riel and his book OO Design Heuristics: http://www.bookpool.com/sm/020163385X. This book categorizes some 60 heuristics or "rules of thumb" that you can use when designing and evaluating a design. Although it is nearly a decade old and the examples are in C++, these heuristics are well respected and worth knowing. You can get a flavor for the book's contents here: http://lcm.csa.iisc.ernet.in/soft_arch/OO_Design_Heuristic.htm.

Refactoring has been defined as improving the design of software without changing its behavior. Or, at least, its externally visible behavior. There are many kinds of refactorings that amount to renaming or moving things. Other refactorings are more "intrusive" in that they call for a more significant shift in the implementation to introduce polymorphism or introduce stronger encapsulation. The most extensive refactorings tend to be about morphing existing code to apply specific design patterns.

This practice of refactoring isn't new. Programmers and designers have been doing it for a long time. What is new is that the practice is better codified and many of the mechanisms used and thought-processes applied are being documented so that they can be disseminated and learned. Foundational in this effort is the book Refactoring: Improving the Design of Existing Code, again by Robert Martin: http://www.bookpool.com/sm/0201485672. I strongly encourage you to acquire it. You can get a flavor for its contents here: http://www.refactoring.com/catalog/.

Another book I intend to buy soon is Joshua Kerievsky's Refactoring to Patterns: http://www.bookpool.com/sm/0321213351. The catalog of refactorings discussed is presented here: http://www.industriallogic.com/xp/refactoring/catalog.html.

Schooling yourself on OO design principles, heuristics, and refactorings will help you become a better designer and developer. There isn't much you can do here that will be a waste of time.

Best regards,
Jim Cakalic
LVL 37

Expert Comment

ID: 13447395

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question