• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does the given code violate any OOP principle or Is there any code smell in it?

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
I have a sample code below.In which i fetch collection of half filled PrefixBeans from database.Then i use a service class to derive the remaining properties of the prefixbean and update the bean.My doubt is since the remaining bean properties are dervied from one or tow bean properties.Should i write the derivation logic in the bean getters or is it ok to calculate the remaining properties in the service class.?If i do in the service class, is it violating any OOP principle?Do you find any code smell here?

The PefixBean will contain the organizationPrefix and existingItemCount already filled by the DAO.



The below service method is used to calculate the remaing fields of the PrefixBean.

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I think your question is answered when you consider another class/service wanting to call the same DAO method and expecting the derived properties to be set.
 
raj malhotra
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,

Thanks for reply.Yes you are correct.Then i have to recalculate the properties for other service.I noticed one more thing , even if only one service method is going to use this DAO but still the current code couples the userid with the derived properties.So unless you supply userid you cannot get the derived properties.

Thanks,
Raj
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raj

In terms of OOP, if you have derived fields, then you shouldn't expose setter methods for them. Your current code allows any calling party to set the value of prefixCapacity to whatever they like.
 
raj malhotra
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes there should not be setter methods for a derived field.This was just a dummy code since i didn't want to paste original source code from my project. And in a hurry i generated all setter and getters.
Thanks for looking into the code.

-Raj
 
reply
    Bookmark Topic Watch Topic
  • New Topic