• Post Reply Bookmark Topic Watch Topic
  • New Topic

Refactoring versus Design Patterns  RSS feed

 
Billy Sang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people, What would you recommend learning first refactoring or design patterns? Or should I learn both at the same time. I'm not really sure were to start, any advice is appreciated.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billy Sang wrote:Hi people, What would you recommend learning first refactoring or design patterns? Or should I learn both at the same time. I'm not really sure were to start...

Erm, neither am I. They're two completely different functions - and usually (hopefully) almost mutually exclusive. Design patterns are there to help prevent problems; refactoring is generally used after you've already got one.

Would you care to elaborate on your question a bit?

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert, but I would think design patterns would be better to learn first. You would then use them when you refactor, but you would also use them when you write your initial code.

Theoretically, if you know patterns well enough, you wouldn't NEED to refactor it, as you'd have done it right the first time...
 
Billy Sang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well basically, I figure that I learn refactoring I can write better code. However, I a lot of the times I see design patterns used in refactoring. Winston, i'm not sure what you mean by mutually exclusive as I just mentioned that I see a lot of design patterns in refactoring.



Fred,

Yes, but not all refactoring deals with design patterns so just because I know design patterns, it doesn't mean I will not have to refactor.

I'm thinking about just skipping the parts that deal with design patterns and coming back to it later.

Thanks for the help.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who says you have to do one first and then the other in strictly sequential order?

Pick whichever one is most immediately interesting or applicable to you right now. After a while, if you get bored or if the other one becomes more relevant, switch off.

And if you're looking at a particular refactoring, and it uses a design pattern that you're not familiar with or find interesting, go study that design pattern for a while.

If you approach your computer studies is sitting down, reading a book cover-to-cover, and then going, "Welp, I've learned that topic, time to move on to the next one," you'll be in for a very rough road. So many things mutually relate to and depend on so many other things in a big ol' tangled web that you have to be wiling and able to jump around from time to time.

And yeah, that can make it difficult and confusing, but if you approach it right, it helps keep things interesting and fresh too. I've been doing this a long time (Not as long as Winston of course!) and I still find myself starting off reading up on one small, supposedly simple topic that I need to know about for the task at hand, and that topic mentions something else I'm not familiar with, so I have to go read up on that, which leads to another and then another until I'm so far down the rabbit hole, Alice and the Mad Hatter have sent out search parties for me and are getting ready to contact my next of kin.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billy Sang wrote:not all refactoring deals with design patterns so just because I know design patterns, it doesn't mean I will not have to refactor.

True...but you will be less likely to have to refactor your code. Knowing design patterns means that when you write code, you will have a better idea of how to write it right the first time. Also, it will help you understand other people's code who have used them.

And maybe not all, but a LOT of refactoring DOES involve changing bad code to use the correct, properly implemented pattern. So IMHO, learning DP helps you in several ways.
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing stops you from using design patterns while you refactor, too. Sometimes a design pattern fits the problem, but you chose not to use it because it would be overkill. You might do things a simpler way because you are making a tradeoff somewhere else. Things change, and its not an overkill any more, and then you go refactor and apply the design pattern
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!