This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Scott Ambler
author
Ranch Hand
Posts: 608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic