Saturday, January 14, 2006

Day 3: Object Design

Previous: Requirements Revised

Now see how easy to move from Glossary to object design. Immediately we can identify our business entity

/**
* represents a Message which can have Text
*/
public class Message {
String text;
}

What we also need is an object which we can ask to create new Message and to retrieve list of Messages. You may call it MessageFactory, MessageManager or MessageHome. Now I’ll call it MessageRepository:

/**
* Responsible for creating new Messages and to retrieve existing.
* We don’t need to delete or update for now.
*/
public class MessageRepository {
public Message create();

public List getAll();
}

We are probably breaking the Single Responsibility Principle here. But currently I find impractical to have separated MessageFactory object just to create a message and send it to Repository then. Do you have another opinion?


Cut requirements to move forward

I still have a long road on the go for the first iteration. Big things are managing Message creation, and whole UI stuff. To move faster, I decided to throw off message creation for now, and to show a hardcoded set of Messages:

public class MessageRepository {
public List getAll() {
List l = new ArrayList();
l.add(new Message("First"));
l.add(new Message("Sec"));
l.add(new Message("3rd"));
}
}

Next: UI Stuff

No comments: