Is any one to comment on my OO Design? Anyone and everyone is invited..

Hi to all design gurus

I am designing an application for lawn tennis match using java to track the score of tennis match .

The input to the application will just be which of the 2 players won a point. Based on this, the program needs to compute and display the current score.

e.g.,

Input( who won)

Output ( sets won by player 1 ?sets won by player 2 ) (for the current set in progress games won by player 1 ?games won by player 2)-

(for the current game in progress points of player 1 ?points of player 2)

Input (Name of player)Output (Score)

10-0 0-0 15 - 0

20-0 0-0 15 - 15

10-0 0-0 30 - 15

20-0 0-0 30 - 30

10-0 0-0 40 - 30

20-0 0-0 Deuce

10-0 0-0 Adv (1)

20-0 0-0 Deuce

20-0 0-0 Adv(2)

20-0 0-1 0 ?0

-

I was planning to come up with very robust solution by applying different design principles like ocp etc.

For a design to qualify as a good OO design, it should be defined in terms of abstraction rather than implementation. Where is the scope of abstraction here?

Uptill now, I have been able to achieve the following OO design:

Following are the main classes :

TennisDelegate [A business delegate class meant for masking the clients from the complex business details]

TennisMatch [A domain object which captures the business logic for the system]

ScoreCard [singleton class, for simulation of real scorecard in a tennis match]

The architecture (This is more of a sequence diagram) is as follows :

Client TennisDelegatePlayerTennisMatch ScoreCard

||| ||

|getScoreCard(1) ||||

|)|instantiates | ||

||player| ||

||-)| ||

||| ||

||| ||

||( | ||

||||

||getMatchScore(player)||

||)||

||||

||||

||| This will update the|

|||)|

||| score cardclass and return|

||| the updated instance of the|

||| score card.|

||||

||||

TennisMatch Class is a kind of business object (domain object). TennisMatch class contains a method

called getMatchScore(int whoWins), by passing the player who wins. This is the main method to update

the ScoreCard class.

All the business logic (tennis rules) for updating the ScoreCard goes here. It makes sence to add

all the busines logic here as TennisMatch is a business object. I am not going into the implementaion

details of the getMatchScore(player) as it is outside the scope of the current discussion.

Brief about TenisMatch class :

This class HAS-A relationship between following classes

(a) ScoreCard (one instance of ScoreCard in the TennisMatch class)

(b) Player (Two instances of Player in the TennisMatch class)

When TennisMatch is instantiated by the TennisDelegate, it initializes the TennisMatch object by

creating a scorecard instance and two player instances. This is analogous to the real world senario

that, when a match starts(instance initailzed in object modelling context), two players will be

on the court and there will be one score card for that particular match. So basically TennisMatch

class has one scorecard, and 2 player instances.

Although it makes sense to create a Player class as player is a real entity in the tennis match, but I cant make out the

usefullness of the player class apart from its name. Other attributes of the player class might include informations like

service consistency, speed, stamina, quickness, strength, or accuracy, but rightnow I dont need these details for the player,

as of now but as requirement evolve, these attribute might be the part of the player class. So is it really a good idea

to go with a player class with just name attribute, keeping in mind that other attributes might pinch in too later.

Brief about the ScoreCard class :

ScoreCardclass contains following attribues, This is a fully encapsulated class, other details like creating singleton etc has

been ommited herefor bravity .

int setPlayer1= 0;// Setsown by player 1

int setPlayer2= 0;// Setsown by player 2

int gamePlayer1 = 0;// Games own by player 1

int gamePlayer2 = 0;// Games own by Player 2

int pointPlayer1 = 0;// Points own by player 1

int pointPlayer2 = 0;// Points own by player 2

--

In my design, player instance is just used to update the individuls set/game/point values depending upon the input of

the player. As an example, if player 1 has been passed to the getMatchScore(player1), so it means I will have to update

the player1's details like setPlayer1, gamePlayer1 and pointPlayer1 (ofcourse by using the business logic/tennis rules).

Please comment on the over all design.

Let me thank you for showing the patience while going through the post :-)

Thanks

Jameel

[5496 byte] By [Jameel.Khana] at [2007-10-3 1:08:32]
# 1

Hi Jameel !!!!!!!!!!

////

int setPlayer1= 0;// Setsown by player 1

int setPlayer2= 0;// Setsown by player 2

int gamePlayer1 = 0;// Games own by player 1

int gamePlayer2 = 0;// Games own by Player 2

int pointPlayer1 = 0;// Points own by player 1

int pointPlayer2 = 0;// Points own by player 2

Why U have decalred it as it.this May be the final.

Aprat from this U would have used the Fcatory Pattern for Creation of Objets.

rajpuniaa at 2007-7-14 18:05:21 > top of Java-index,Other Topics,Patterns & OO Design...