This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Class Design

 
Jay Richards
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am starting to write a Java program and i need your help guys on how make a good design on the program i will be writing.
assuming i have a class TaskInfo
class TaskInfo {
Person person;
private TaskHistoryBase TaskHistory[];
}
Now my concern is, Person class will be compose of different classes like
1. PersonalInfo
2. ContactInfo
3. BusEmpInfo
4. FamilyInfo
How should I design Person class? Can i create the person class that
extends the 4 other classes. Is that possible? And what should my Person
class in my TaskInfo class should be private or public?
Thanks a lot!
 
Vijayakumar Arya
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Class design is not a complex thing, it is just the way what we realise the entities are. In you case you say that Person has PersonalInfo, ContactInfo, etc.. these are to be a part of the Person class because it belongs to the entity called Person.

All other will be common information can be grouped in a single class.
You just replicate classes as how do you realize the objects.
 
Jay Richards
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
Jay Richards
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
assuming i have the ff code:
class Person{
protected PersonalInfo m_personalInfo;
protected ContactInfo m_contactInfo;...
}
class PersonalInfo{
String m_firstName;
String m_lastName;

getFirstName(){
return m_firstName;
}
}
class sample {
Person person = new Person().....

how do i call getFirstName() of PersonalInfo in the Person class?
assuming there were two the same getFirstName method on both PersonalInfo, ContactInfo class,
how to i call the specific method?
thanks in advance.
 
Vijayakumar Arya
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
First you have to get the PersonalInfo of the Person and then you have to get the firstName.

or you can have a method in the Person class itself to get the firstname

I prefer convention 1.
[ February 11, 2003: Message edited by: Vijayakumar Arya ]
 
Jay Richards
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Vijay.
-Cyber01
 
Hari Gangadharan
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cyber01,
You are not respecting the Javaranch's official policy on displayed name. You have to change your display name to "Firstname Lastname" as described here:
http://www.javaranch.com/name.jsp
[ February 11, 2003: Message edited by: Hari Gangadharan ]
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Jason

Welcome to JavaRanch! Please adjust your display name to meet the JavaRanch Naming Policy.
You can change it here.

Thanks!
[ February 11, 2003: Message edited by: Marilyn de Queiroz ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic