Re: design sanity check/advice
- From: "Nick Malik [Microsoft]" <nickmalik@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Jun 2006 07:26:21 -0700
Hello Gary,
"GDW" <gdw_62@xxxxxxxxx> wrote in message
news:1151373189.375355.149440@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm relatively new to "real" object-oriented design/development (i.e.
patterns/refactoring etc.) although I've been working with OOP
languages for quite some time. I've been doing a lot of
reading/research in order to take it to the next level and am
incorporating it into a new project I'm working.
I like your approach. Sounds like the way I broke into OOP as well.
The app is a survey engine developed using Java/Spring/Hibernate.
Surveys contain pages which contain questions (different variations of
multiple choice and essay-type). Surveys exist in 3 distinct phases:
survey design, survey response entry and survey analysis/reporting.
sounds like three different 'views' but two 'models' (to use the terms from
the somewhat dated 'Model-View-Controller' high level pattern).
You have a view that allows surveys to be created. The controller builds
survey-model data when this view is active. You have a view that presents
the survey. The controller uses survey-model data to drive the pages and
collect information into the response-model. You have a very similar view
that presents the data from the response-model in a reporting interface.
I've started out with a domain model which represents just the design
phase of a survey lifecycle.
I hear you saying "I'm starting with the survey-model... I'll get to the
response-model later." Correct me if I'm hearing you incorrectly.
The classes contain just the information
which needs to be persisted to define the structure/layout of the
components.
e.g.:
OK, now this is odd...
public class SurveyDefinition {
private Long id;
private String title;
private String description;
private List pages = new ArrayList();
what is a SurveyDefinition? If it is a model, then why does it have a
'page' construct in it? Perhaps I'm not understanding, but is the page
intrinsic to the survey, or is it just a display mechanism? If I was to
access your survey on my smartphone, would I still get the same number of
pages? (Gosh, I hope not, although most of the web is completely unusable
from my phone).
Also, I'm a C# person, not a Java person, and perhaps I'm just missing
something, but in C#, the ArrayList() construct is not strongly typed. I
can add any object. When you want a list of objects, it is nearly always
better to store it in a strongly typed arraylist construct. So, wherever
you put that list, make it strongly typed.
public abstract class QuestionDefinition {
private Long id;
private Integer questionNumber;
private String prompt;
private boolean answerRequired;
private PageDefinition page;
OK, so same concern. Why does a question care about what page it is on? If
'PageDefinition' were a set of configuration settings that drive the
formatting of the display, I'd suggest renaming it to 'displaySettings' or
something a bit more descriptive. Otherwise, I'd seperate the data about
the question from the data about how to display it. If anything, the page
contains the question, not the other way around.
public abstract class MultipleChoiceQuestionDef extends
QuestionDefinition {
private boolean singleAnswer;
private List choices = new ArrayList();
.
Look at your design from the standpoint of what you want to DO with it. Do
you want to be able to say "page.displayYourself()" ? If so, the the page
object should know what questions are on the page and each question object
should know how to paint itself. Note that collecting responses is a
function of displaying a page, and then collecting responses... so it is OK
to say "page.displayYourself" in the course of constructing the form that
the user will respond to.
This initial design was really just created to get my feet wet with
Hibernate to make sure that I could get all of the ORM
inheritance/polymorphism/association mechanisms working. I have kind
of a vague idea of where I want to take this but I want to make sure
that I'm not too far off base before I get too far into the design.
Be careful of your tools. They can make it easy to code, and easy to mess
up as well. In other words, moving up from a .22 Caliber pistol to an AK47
doesn't make you a better shot... it just means you have the ability to
shoot your foot off WITH GUSTO!
In other words, work on the design first. Then fit that into the tools.
Does it make sense to have the survey design phase entities (e.g.
SurveyDefinition, PageDefinition, QuestionDefinition etc.) as separate
classes distinct from the survey response entry phase entities (e.g.
Survey, Page, Question etc.)?
It does if you are talking about pages that are used for the different views
(Build-Survey view vs. Display-Survey view). The data model for the
survey-data would be the same for both scenarios and should be a single set
of objects.
I'm thinking that the survey response
entry phase entities really are different animals with richer behavior
and that these could be created by passing the definition entities
into a factory/creation class/method.
I haven't had my coffee yet, so forgive me, but I have no idea what you
meant. I hope I answered your question somewhere else.
Are there any (other) strategies/patterns etc. that I might want to
pursue?
Any suggestions/advice/admonitions/coaching/counseling/encouragement
and/or hot stock tips would be greatly appreciated.
Hot tip: don't take investment advice from someone who works for a living.
As for your design, it doesn't jump out at me as a good example of OOD.
Maybe it's all there and I just missed it. That's possible.
Let me encourage you in a couple of ways:
1) Excellent first attempt.
2) Please consider reading "Head First Design Patterns" or "Design Patterns
Explained"
3) Remember that much of the real power of OOD comes in the relationships
between objects, not in the object definitions.
Is this reply helpful?
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
.
- References:
- design sanity check/advice
- From: GDW
- design sanity check/advice
- Prev by Date: Re: design sanity check/advice
- Next by Date: Re: Is this correct?!!!
- Previous by thread: Re: design sanity check/advice
- Next by thread: Re: design sanity check/advice
- Index(es):
Relevant Pages
|