wood burning stoves*
The moose likes OO, Patterns, UML and Refactoring and the fly likes What's the relationship between dessign patterns and Refactoring Databases? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "What Watch "What New topic
Author

What's the relationship between dessign patterns and Refactoring Databases?

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
I've learned some general design patterns from Head First Design Patterns and other books. And I konw in specific area these design patterns will be developed.For example, there are some J2EE patterns developed from 23 general patterns. Is your book such a book like Core J2EE Patterns? Does refactoring process use lots of patterns?

What is your book mainly about? It seems it's a book more on Database

Thanks.
[ July 24, 2006: Message edited by: Loius Wan ]

To be or not to be. It's a question.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi, I was thinking since I'm doing this for quite sometime. It would seem that every database table can be related to a single class. There's a rule saying, "Favor composition over inheritance", which I think applies quite the same in database design. Consider the following example:

class Person
{
String firstName;
String middleName;
String lastName;
String mothersName;
String fathersName;
}

and your database entry would probably have

------------
persons_tbl
------------
person_id
first_name
middle_name
last_name
mothers_name
fathers_name
------------

in my strategy, I refractor this class and database table to have the following composition


class Person
{
String firstName;
String middleName;
String lastName;

Parent parent;
}

class Parent
{
String mothersName
String fathersName
}


your database tables

------------
persons_tbl
------------
person_id
first_name
middle_name
last_name
parent_id
------------

------------
parents_tbl
------------
parent_id
mothers_name
fathers_name
------------


I hope you understand hehehe.


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Lian
Greenhorn

Joined: Sep 16, 2002
Posts: 1
There is another possible solution. The class Person mixed in fact 3 Persons in one instance, the person itself and the persons mom and dad. Isn't it better to go for a more general approach ?
class Person {
String firstName;
String middleName;
String lastName;
Person mom;
Person dad;
}
So there is no need for a own class Parent, instead you have relations.
Lian

----------
"The best thing about the future is that it comes only one day at a time. " - Abraham Lincoln
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Timothy Sam wrote: It would seem that every database table can be related to a single class

This is one of the big myths of Object-Relational mapping. This mental model seems deceptively attractive, but it will always catch you out in the real world.

Fundamentally, a class is a colection of behaviour which may happen to have associated data. A database table is a collection of data which may happen to have associated behaviour.

In your post you seem to favour the "data" view of the world. Your classes have no behaviour, so (naturally enough) they seem close in concept to a database table. I hope you understand that real classes are not usually like that.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Scott Ambler
author
Ranch Hand

Joined: Dec 12, 2003
Posts: 608
To answer the original question, the book is a lot more like Refactoring than it is about Design Patterns by Gamma et. al. Yes, there is great similarity in the formatting of the material.

When it gets right down to it, a pattern description is merely a common formatting of what would normally be called a "good design practice" or "good design strategy". I guess the same thing could be said about a refactoring description, although in this case it would be a "good redesign practice/strategy".

- Scott


<a href="http://www-306.ibm.com/software/rational/bios/ambler.html" target="_blank" rel="nofollow">Scott W. Ambler</a><br />Practice Leader Agile Development, IBM Rational<br /> <br />Now available: <a href="http://www.ambysoft.com/books/refactoringDatabases.html" target="_blank" rel="nofollow">Refactoring Databases: Evolutionary Database Design</a>
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Loius Wan:
Does refactoring process use lots of patterns?


You may want to look into Joshua Kerievsky's: Refactoring to Patterns
Addison-Wesley Professional
amazon US

Refactoring to Patterns Home Page
[ July 25, 2006: Message edited by: Peer Reynders ]
Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
Thank you for your reply.

It seems there is some relationship between them(Refactoring and Design Patterns). I also have a question in my last post: Is it a specific usage in the database field? Like Core J2EE Patterns, it's a specific usage of general patterns in the J2EE field.

In that case, I think it's better for me to concerntrate on the Head First Design Patterns first. Then when I master lots of general patterns, I will go thru the field specific usage of these patterns.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: What's the relationship between dessign patterns and Refactoring Databases?