• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

OO design

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm making an application which will use 3 kinds of obects:
User (id_user,id_group,name,surname,email)
Group (id_group,name,color)
Application(id_application,name,...)
they represent users, groups in which they belong,
and applications at which they have access.All info is
in Database in 4 tables Users, Groups, Applications ,
Relations_Groups_Applications. I have two alternatives at this:
(for saving info in DB)
1)Making 3 objects User,Group,Application with their methods
add, update, delete which will make the saving of the objects
in DB.
2)Making objects User,Group,Application,UserList,GroupList,
ApplicationList and methods add, update, delete of the UserList,GroupList,ApplicationList which will make the saving of the objects in DB.
Which is the better approach? Thanks
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Catalin,
I am assuming a few things regarding the basic design of the classes here:
1. The Group class will have an aggregation of User class.
2. The Application class will have an aggregation of Group class.
That is the hierarchy I think you have. Please correct me if I am wrong.
Going by the above assumption, my design will have a mix of both your techniques. The actual statements to save the object information in the database will be in add, update, delete methods of the individual classes. Each of these methods will have all the required information passed as parameters.
I will use the ApplicationList, GroupList and UserList collections to save multiple instances of the respective objects. The add, update, delete methods in the list objects will iterate through all the elements in the list and call the respective add, update, delete methods of each idividual objects.
Please consider that the add, update, delete methods of the any Application object will have to iterate through the Group objects that are part of that Application object and call the add, update, delete methods of the respective Group objects. Smilary the methods for any Group object will have to iterate through the User objects that are part of that Group object and call the respective methods.
I hope that this helps.
Thanks.
Sanjib.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look at java.security and java.security.acl packages. They have used some good patterns for similar situations.
 
Catalin Bren
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Group contains a list of users (Vector of User) and a list of applications (Vector of Application) at which a group can have access. My question is if I should make methods in User that will add,update,or delete it from database or to make them in
the Group object calling them passing an User object
(addUser(User o)) and adding them in the Vector of users in the Group. The same question for the Apllication object. To save it
in the DB is it necesarry to call the methods Add() of this object which will save it in DB or to make an ApplicationList and call the methods addApplication(Application o) of this.
I looked at the java.security.* it seems they used the second approach. Frank (Carver) if you have time to answer I'll
be gratefull. Thank you all.
 
Catalin Bren
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Entity Beans (entreprise java beans) (javax.ejb.EntityBean) they
use the ejbCreate(for insert in DB), ejbStore (for update in DB),
ejbFind (for select in DB wich returns an enumeration of objects) on the same object to access the database. Do you think
this is the best approach ? Thank you.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar problem but more complex one now. Can you help me?
I'm making an application which will use 3 kinds of obects:
User (id_user,name, departments, majorDepartment, ...)
Department (id_department,name,Users, ...)
Role(id_role,name,User, Group...)
They represent users, departments in which they belong,and Roles at which they have access.(the role has many access object)
All info is in Database in 4 tables Users, Departments, Roles, and the strange thing:"Users_Departments_Roles".
The business logic seems very complex:
1. A user can work in several departments in the same time; (but he can has only one majorDepartment, and he can change his major after login)
2. A user have many security roles, but his roles will be different in his different department;
3. When he log into the system, the system can only provide him his majorDepartment Roles.(For example, Bernie's current majorDepartment is Sales department, he can't view or update the information of finance department.)
So the Table "Users_Departments_Roles" will have to contain (User_id,Department_id,Role_id)
Is it a relationship of "many to many to many"
It seems terrible, but I can't think out other solution.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Bernie,
I will try to help though I must warn you my practical experience is scarce.
First let's try to set up the relationships among User, Role and Department
1. A user can work in several departments in the same time; (but he can has only one majorDepartment, and he can change his major after login)
There is an association User--Department whose role name at the Department-end is majorDeparment.
The Department has an association to multiple Users who are allowed to work at.
2. A user have many security roles, but his roles will be different in his different department; That is, a set of Roles is associated to a given pair of Department-User instances. Make the Deparment class to hold a map whose keys are User and values are a set of Roles.
When he log into the system, the system can only provide him his majorDepartment Roles.(For example, Bernie's current majorDepartment is Sales department, he can't view or update the information of finance department.)
The Deparment that receives the log of a User looks her up into the map. If she is an authorized User, she will be held by the map and the returned object is her corresponding Set of Roles.
are the above lines on the right path?
[ September 21, 2003: Message edited by: Jose Botella ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Catalin Bren:
Entity Beans (entreprise java beans) (javax.ejb.EntityBean) they
use the ejbCreate(for insert in DB), ejbStore (for update in DB),
ejbFind (for select in DB wich returns an enumeration of objects) on the same object to access the database. Do you think
this is the best approach ? Thank you.


IMO EJB should never be used unless there is a clear TECHNICAL requirement for them (and I don't mean the CEO saying that EJB should be used because it looks cool on the product brochure).
A technical requirement for EJB is almost purely limited to distributed applications that need largescale database access with relatively long transactions.
In most cases EJB is overkill, needlessly complicating design and reducing performance.
 
Bernie Gu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,Jose Botella
I think your reply is one type of solutions. But I still have some questions.

Make the Deparment class to hold a map whose keys are User and values are a set of Roles.


I am using Hibernate to help me O/R Mapping. And I don't know if Hibernate can save the map(user and values of a set of roles) in my persistence layer. The document of Hibernate didn't mention it. I have ever used Toplink4 and castor, but unfortunately they don't support that way too.
Maybe I have to handler the map in department manually....
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic