Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What to put in my beans?  RSS feed

 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I know this is a strange question to ask, but really I am lost on how to organise my bean! My problem is this; should I create a session bean for each particular domain object I have? or I should create a session bean for each allowed action on such a domain model?

For example if I have the entity ShoppingCart then should I have a session bean named ShoppingCartBean that has all the methods related to the management of shopping cart (such as addItem, removeItem, etc)? or I should have a session bean such as AddItemToShoppingCartBean, RemoveItemFromShopping, etc?

I am asking because I am reading a book where for example a bean named PlaceBidBean is used rather then a BidBean that contains method such as placeBid, cancelBid, getBid, etc!

Regards,
Sim085
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon,
Having a verb ("Place") in an entity bean name is odd. What do they have in the bean as attributes?
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Simon,
Having a verb ("Place") in an entity bean name is odd. What do they have in the bean as attributes?


I give another example from the book (note the book is very good and I like it, I am asking this just to get a better feel of how to use beans). The class is as follows:



However in my mind I would have created a bean AccountBean and in this I would have put the createAccount() and addBiographicalInfo() methods but also any other methods related with an account, such as; deleteAccount(), shoppingHistory() etc...

What I am scared of is that if I create a Bean for each potential action then I'll be summersed in beans - while if I create a Bean for each domain model then I'll have very complicated beans (ie - a lot of code in one place).
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends... Others create a bean for each use case. So AccountCreatorBean would be a "legal" example.
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Dillinger wrote:It depends... Others create a bean for each use case. So AccountCreatorBean would be a "legal" example.


That is an interesting idea I'll see the use cases I have and see if it works fine for me.
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have thought a little about this and I have arrived to the following conclusion. If in my domain model I have an object Bid, then I will definitely need a Bean which responsibility goes from anywhere creating a new Bid to deleting Bids and return all current Bids. However there might be occasions where more bussiness work needs to be done. In such a case I create another Bean which wraps the Business Logic assumed in a use case. Such Bean would then make calls to the original BidBean accordingly.

What do you people think of such a design?
 
pankaj vijay
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Simon
You are asking that how should use session bean. The my idea is if there are three 5 co-related tables for eg. If i am storing information about an employee then i will have tables like personalDetails, AccdemicDetails, ProfileDetails etc.... now these tables are related with primary & foreign key mapping.
so in this case i will have 5 different Entity classes but If i am submitting all information at a single time then i will use only one session bean because i will use cascading ="all" option in entity bean class.so if i will persist personalDetails object then other class object will also persisted automatically with mapping of primary & foreign key. So in this case one session bean class for 5 entity bean classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!