aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes General IS-A, Has-A relationships. Class Designing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "General IS-A, Has-A relationships. Class Designing" Watch "General IS-A, Has-A relationships. Class Designing" New topic
Author

General IS-A, Has-A relationships. Class Designing

Harish Moolchandani
Greenhorn

Joined: Mar 12, 2010
Posts: 23
I'm doing a project first time using MVC-DAO. And this time I want to make proper bean files and classes. But its so much confusing.

There will be 5 users in the system.
consumer, employer, manager, admin, public reviewer

Adult members of a household can become consumers.
The consumer can opt for various schemes and employment is one of them.
We have only taken one scheme currently which is Employment, but more will be added in future like health and poverty alleviation schemes.

So these are the classes I've considered so far.

User - Abstract Class
Person - Interface (Had to take as an interface, some classes need both user and person features, so have to make one of them as interface).
Household Is An User - (Household extends User)
Consumer Is A Person - (Consumer implements Person)
Household has many Consumers
NonConsumer Is An User and A Person - (The consumer will not be a user, a household will be. But the other persons such as Admin, manager, employer can be users. So took another class)

This is more confusing -
Employee Is A Consumer
Employer Is A NonConsumer
Employer Has Projects - (Employer will provide projects)
Project Has Jobs - (Job requirements based on Projects)
Job Has Employees - (Need to see who worked for this job)
Employee Has Employments - (The Employee has Employment History, so that he/she can view the jobs they worked at)
Empoyment Has A Job - (even more Confused)
Job has A Project - (Job can reference back to which project it belongs).

Please tell me what's wrong going here, I have a feeling that this model is not correct. Any classes to add/remove. Please help me correct it.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Without explicit requirements for the Employment scheme, there really is not way to judge your design or even provide meaningful suggestions. What is the business case and the problem statement? What are the requirements? Your source of confusion most likely comes from not knowing these things.
Harish Moolchandani
Greenhorn

Joined: Mar 12, 2010
Posts: 23
It's like this, a consumer can choose to apply for a job provided by employer.
After he/she got the job, its information is stored in a seperate table.

Id, JobId, ConsumerId, EmployedFrom, EmployedTo, TotalAttendence, PreviousAttendence.

I named this table as Employee. A consumer can find out its previous or current jobs through this table.
But the class Employee will inherit Consumer. So, there will be a problem, since according to class Employee, one consumer can be employee of one job. But this is not what I want.
So I renamed the table to Employment, and took a class called Employment which will have all these details, and the employee class will have a List<Employment> named employmentHistory, through which I can track what jobs this consumer had in past.
But the naming of the class and relationships doesn't feel right.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Object-oriented Class design and relational table design are different tasks. It is better to not make decisions about one thing based on another thing from a different context. Class design should be focused on how the temporary objects of your application will communicate with each other. The relational table design is based on permanent storage of application data.

I suggest that you first create a design without any inheritance or composition. Simply model the entities based on your existing technical requirements. If you have trouble with this, then you need to work on the requirements some more.

It's like this, a consumer can choose to apply for a job provided by employer.
After he/she got the job, its information is stored in a seperate table.


This does not imply any inheritance. Everything you have stated about your design is being created in your mind only and is not based on anything.

Based on what your requirement is, there are three classes. Consumer, Job and Employer. That is all. The only behavior that you have so far is "apply."
Harish Moolchandani
Greenhorn

Joined: Mar 12, 2010
Posts: 23
Well its like this,
A consumer will be a member of household.
There can be multiple consumer related to a household.
This household have one username and password.
The household user can view its consumer's details, including the projects done and locations.
While registering for household, user can add consumers there or can add after registering household.
After registration this household will be verified by admin.
Employer can provide projects and provide job related to that project, and consumer will apply for those jobs.
And there's more than this.
I've thought the project and its flow. Its just I cannot implement it in a class design.

Now the problem is, if household user clicks on consumer details it should also show its employment history and work done in the past. So I take a class named project and I can insert a Project object in consumer.
But any user can see any project and it should show employees working on that project with their roles and location.
So, isn't its confusing, project has consumers, and consumer has project.
Also Employer has projects.
If I has to show which employee is working under particular employer, I've to choose a project first from the employer and from that project I will select employee list.

Sorry if I sound stupid, but I've to do everything by myself alone and no one to guide, and there's so much less time to make it.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Sound object-oriented analysis and design skills are difficult to acquire. It will take at least two years to get a strong, workable foundation, possibly three years. As a beginner, it would better for you to focus on completing a design rather than trying to make it perfect and waste time over-analyzing the possible designs and faults. Over time, it should become easier and you should learn from your mistakes.


Good luck!
Harish Moolchandani
Greenhorn

Joined: Mar 12, 2010
Posts: 23
Ok, jimmy
You are right, I will waste my time if I try to make it perfect.
But I always try to do new things, if I won't go for new things then I cannot learn anything new from my projects.
This is my first MVC project and I learned there's much more in project designing than MVC and that's design patterns. I'm implementing the sun's suggested method of DAO pattern (the factory pattern) in this project.
I learned other things as well, such as more clear concepts of MVC. I always knew the theory but never used it in any project.

I'll follow your advice and just try to complete my project on time.
Thanks for all the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: General IS-A, Has-A relationships. Class Designing
 
Similar Threads
What it takes to be an architect?
Advice needed - Urgent
Inheritance structure and polymorphic designs
Jobs In UK Site Launched
Outsource remote development and crisis.