Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with determining classes 2

Status
Not open for further replies.

mmaz

Programmer
Nov 22, 2000
347
Hi there,

I have to build a simple application (used by less than 10 people) that must run on Linux and Windows, so I've decided to use Java. We do not have a designer here, so I have to do the Analysis and design. I know the concepts of OOAP, but I'm having a bit of trouble to identify the classes and their methods.

I was hoping that somebody could help me with this (I'm the only programmer in my organization).

Basically, we have a directory of companies, and the administrator should have the ability to maintain the directory (add, modify and delete companies). A few different surveys were also given to some of these companies and the regular users want to be able to look at the surveys results and look at each company's answers.

I have identified 5 classes, Company, Survey, Employee, Administrator and User:

--------------------------------------
class Company
- Behaviors: maintain company details
- Properties: name, address, phone, number of employees...

class Survey
- Behaviors: search survey results
- Properties: name, questions, answers

class Employee
- Behaviors: authenticate
- Properties: id, name, role

class Administrator extends Employee
- Behaviors: maintain companies
- Properties:

class User extends Employee
- Behaviors: search companies
- Properties:

---------------------------------------

Would somebody be kind enough to comment this? I know it's not right. I have trouble separating the responsabilities of a person and those of an object.

Where should I put the methods addCompany, modifyCompany, deleteCompany and searchCompany? These goes in the Company class, right?

Any help would be greatly appreciated!

Thanks in advance,

Marie
 
Marie,

Maybe you should have a 'CompanyCollection' class which has those methods as well as collection classes for Survey, Employee, etc. I'm basing this on another post to this forum which I'll have to look for.

As for the Survey class, I think you'd want to have 2 classes: one for the actual survey questions and possible answers and another for individual companies' answers to those surveys.
 
Here's the URL for the thread I was talking about, started by DonQuichote:

thread678-487289
 
Thanks for your reply, varocho.

I built a VB project at school a few years ago, and I remember using collection classes. Do you know if these apply to Java as well, cause I can't remember reading about them in my Java books?

Also, what are the steps would you suggest for me to develop this application? Obviously, I have no experience in OOAD, but this is something I really want to do well. Going back to school is not an option. Buying books is, but I have a few, and they're not really helping ("UML Distilled" and "Doing Objects in VB").

My problem is, I understand the theory, but I have difficulties putting it into practice.

For example, which classe should be an interface, where does this method belong, do I need a class for this and I could go on and on.

I think the best way to learn OOAD would be to have a book full of examples. The specifications of the application would be spelled out, the reader would try to define the classes, methods, properties, write the use case and draw the use case diagram. And then the recommended solution would be available.

If anybody knows of such a book, please please let me know.

Thanks,

Marie
 
Here's the URL for a 'Collections Framework Overview':


As for your design questions, I don't claim to be a guru, but I think what you have so far is a good start.

It seems to me you'd use an interface when the implementations of the methods specified in the interface may need to change in the future and/or aren't known until run-time.

Have you thought about developing 'use cases'?
 
Thanks for the link. I've studied Collections before, but they're just (as far as I know) a special kind of array, so I'm not sure how I would use it within this context.

I think I will just plan as best as I can, and then start coding. It's not a very big project and the timeline is pretty flexible, so I will learn from my mistakes. Maybe I could publish my memoirs after that!! :)

Thanks for your advice, varocho!

Marie
 
Marie,

This thread might be of some use to as well:

thread678-280308

Another good book is "Beginning Java Objects: From Concepts to Code" by Jacquie Barker.

You might also want to consider buying/developing 'utility classes' for things like string/regular expression processing, database access, file i/o, etc.
 
Hello, Marie and varocho.

Since your app will be very simple, IMHO you must desing it in a two tiers way.

Classes as "Company", "Survey", "Employee", "Administrator" or "User" are DB entities wrappers, and should be placed in the low layer.
These classes will be used to store entities data and they won't contain functionality but data format validation. This classes will be used in upper layer(s) to store and manage data.

Functionality and visual design/logic should be placed in the upper layer. So, in an event handler (as buttonAdd_onClick) you will write presentation logic (as textBoxCompanyName.enabled = False) and bussines logic (as Declare myCompany As New Company; myCompany.name = textBoxCompanyName.Text; myCompany.DBSave(); )

If you expect your App to grow, or you want to learn more and can afford a longer development time, you must design it in a three tiers way.

Regards.

Polu.
 
A couple more books I recommend:

- "Bitter Java"
- "The Pragmatic Programmer"
 
Thanks varocho.

I bought "Teach Yourself Object Oriented Programming". It seems decent enough...
 
cool! I added it to my bookmarks. If I could give you a second star, varocho, I would!

Thanks for the help!

Marie
 
Marie,

I'd be reluctant to give you any explicit design instructions just based on what you've said here. Although the details you've put down are clear and concise the reality is that people will draw their own conclusions and mental pictures and they will more than likely be of a different flavour than the reality of what you've actually got.

Personally, and this is absolutely without intention to be disrespectful to anyone who has posted advice already, I'd therefore advise against taking too much explicit advise from someone who isn't directly involved in your problem domain.

Thinking about collections and tiered solutions is, IMHO, putting the cart before the horse a bit here. Make sure you are 100% happy with your design first and then move forward with the certain knowledge that it will be modified at stages throughout the development and the design must be robust and flexible enough to handle this. Get the flavour of your design right and concentrate on roles and responsibilities before you start thinking about properties, ids and methods.

If you are inexperienced I would advise staying away from designs that you aren't thoroughly comfortable with (tiered solutions for instance).

Just make sure that your design models the reality of what ACTUALLY happens, as opposed to modelling a design that would give a solution to your problem. Designing a solution will generally only work for the here and now. The only certainty if it is a useful system is that requirements will grow and change and your system must change with it. If you model the reality then your system will adapt to change in the same way as the reality does.

I may be teaching you to suck eggs here, but an effective way to get the ball rolling with your design to write up a definition of the system including all the roles and responsibilities you want to model and the way in which the system is to behave. From this the Nouns within your description will most likely map to your entities/objects and the verbs to the methods of the former.

Hope this is helpful.
 
Thanks, Cairnsay. Great advice! I have to say it's a very good thing that I can take as much time as I want for this project... :)
 
No problem, happy to help.

Should you want any further advice I've set the email notification, so just post to this thread and I'll do what I can.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top