• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question regarding POJOs  RSS feed

 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to learn code maintainability and reusability is part of that. So I am going through some of my old code and trying to find places that weren't designed well and modifying it. I did enhance two plain old java objects but am concerned on what other developers would do. I have a person class and a customer class. Each class is independent of one another. The customer class takes a person object as a parameter. Would you have both customer and person or just customer. Any information is appreciated thank you. I did it this way so if I needed to update Person I wouldn't have to modify both person and customer plus other instances of the customer class. Personally I feel like customer is a subclass to person. I may add an employee and manager class later which would also be a subclass of person.



 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Sexton wrote:I am trying to learn code maintainability and reusability is part of that. So I am going through some of my old code and trying to find places that weren't designed well and modifying it. I did enhance two plain old java objects but am concerned on what other developers would do. I have a person class and a customer class. Each class is independent of one another. The customer class takes a person object as a parameter. Would you have both customer and person or just customer. Any information is appreciated thank you. I did it this way so if I needed to update Person I wouldn't have to modify both person and customer plus other instances of the customer class. Personally I feel like customer is a subclass to person. I may add an employee and manager class later which would also be a subclass of person.





An example of creating a new instance of customer

 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's easier to judge whether or not you're making good design choices if you have a context. This is why I prefer to do test-driven development (TDD) because the tests provide the context in which I can better see the consequences of my design choices. Without a context, you're pretty much just guessing and this often leads to over-engineering the design. It's kind of like getting all dressed up with nowhere in particular to go. How do you decide what pants to wear if you don't know what the occasion is? Shorts? Dress pants? Jeans? Leather? If you don't have a context, you'll probably just end up with a design that's like a pair of pants with one leg that's knee-length, khaki in front, denim in the back, the other leg made of lightweight wool in front, with a slight break, pleats, and skin-tight leather with studs in the back.
 
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Junilu for insights !!! Do you know any testing framework for MYSQL ? I need to TDD for Mysql. Or atleast unit test ?
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Sexton wrote:...Personally I feel like customer is a subclass to person. I may add an employee and manager class later which would also be a subclass of person....

Sounds right, but I agree with Junilu: how detailed or sophisticated you want your hierarchy is likely to depend much more on what you need to do with "people" (or "customers" or "employees") than whether they're perfectly structured.

One thing that might be worth mentioning: People, in general, are notoriously difficult to identify, because all the things we normally use (name, date of birth, gender, blood type, etc..) don't guarantee uniqueness, even in combination; and many of the other things that we might use - like address or telephone number - can change. Furthermore, there are laws about what companies are, and are not, allowed to ask.
I have a friend from Morocco, for example, who doesn't even have a full date of birth on his passport - just a year.

Employees, on the other hand, are likely to have a number, so...how do you match employee "John Smith" with the person "John Smith", and know that he's not one of the 46 other "John Smith's" that you also have as customers? It's also perfectly possible that employee "John Smith" is also a customer.

The simple answer is that there's no "right way" to do it - although it's good that you're thinking about it. I'd go with Junilu's advice: let the business - and your testing - determine what the best approach is.

HIH

Winston
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:. . .
I have a friend from Morocco, for example, who doesn't even have a full date of birth on his passport - just a year.
. . .
When I last went to Africa many people didn't even know which year they were born in.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!