• 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

Was asked to make a simple OOP example, only reply I got was "thats wrong". Looking for critique

 
Ranch Hand
Posts: 31
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Idea for my simple example:

Since it was for a company, why not make a simple company example I thought (that would be good enough to demonstrate some understanding of OOP) and it was about a company employing developers who work on some projects.

Company with instance variables like number of offices, workHours and employees, location.
Developer class that extends the Employee class, since there are different types of Employees but there is not need to make a class for each in this example
since it would be redundant(like tester/janitor/secretary/CEO/manager  etc.)
Project that developers work on which is in a aggregation(developer 'has a' project) relationship.
WorkingHours interface that the company and developer class implement each in their own way. Since the developer could have flexible working hours etc.
While some other Employees that work in offices would not have such an option I made this into an interface.

UML below:





The reply I got was basically along the lines, thats wrong/bad example. Without going into any details and no critique was given.


I wanna learn from my mistakes, so I came here searching for some constructive criticism. Helpz:)
 
Bartender
Posts: 242
27
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly was your assignment? Just to come up with an example of OOP? Because I don't see any real mistakes in the description itself; it shows OOP. Was the UML part of the assignment, and if so how accurate does it need to be, do you need to code this out later? Because there are some mistakes in the UML. If it's supposed to be a UML you can later code off of, then there will need to be some corrections.

UML is not loading on this page but works if you go to the source for it. Here is the embedded version:


UML Feedback (not in any order, just as I notice it)
- Why does Company implement WorkingHours? Did you mean employee?
- How would workTime() function? Work has a start and end time, but there's only one function. What would be an example return value from it?
- whatIsTheDeveloperWorkingOn() is not the best method name. Perhaps getProjects() or would be better.
- You declare several variables as "set". This is not specific. A Set of what?
- You underlines the class names in the UML (all besides Project). This means they are static, I believe.
- No multiplicity is stated from project to developer. How many projects are there per developer? If there's only 1, then it can be 1 to 1. If not, it should be declared like: 1 developer to 1... project, or 1 developer to 0... projects (if they can not be working on anything).
- I'm not sure experience as an integer field makes much sense. What is 1 experience? Years?
- No return types are specified on the UML diagram. For example: getEmployeeInfo() - what does this return? A String? A custom EmployeeInfo class?
- No constructors specified. This means that your private fields can never be set in any way.
- addProject() takes no arguments. What project are you adding?
- Make sure all your fields make sense where they are. For example: what is the purpose of a Company having time?
- Company should probably have some employees. Right now it has a count of employees, but not any actual employees.
Try generating code from that UML (either using a tool or manually), and write it EXACTLY as it appears in the UML. See what you can do with it. If it doesn't function, then first make adjustments to the UML, then code exactly what it says again.
 
Philip Freeman
Ranch Hand
Posts: 31
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, now I see that my UML is crap!
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your first design is not going to be good.  IMO, UML diagrams are mostly good for seeing what's wrong with your initial ideas but you need to have the skill and sensitivity to recognize the things that are wrong.  Why does a Developer have a projects attribute and then a numberOfProjects attribute as well? Why does a Developer have a projects attribute at all?

The point of writing a program is to do something useful. That "useful" thing is what provides the context for assigning behaviors, roles, and responsibilities. That's what Object-Orientation is about. Attributes, which you and most beginners seem to be more concerned about, are there to facilitate the behavior of an object.  Without a purpose, you're more likely to over-engineer and/or mis-assign behaviors and responsibilities.

What useful thing does this design allow you to accomplish? I see no mention of that in your post. What you did was basically say "I'm going to build something. I'm going to need some wood, nails, screws, a hammer, a saw, a screwdriver, etc. ..."  You started collecting and amassing a pile of materials (classes, attributes, an interface, etc.) with no clear idea of what you were going to build. You just have a bunch of "stuff" that you're (maybe) going to put together to do something useful (not clear what exactly).

If I were you, I would forget about the UML diagram and all those classes you conjured up in your head. Start with an idea of a useful thing. Then think of what you're going to need to get that thing done. Doing that is like saying "I'd like to build a bird house." Now you have a context.  Then you say, "I'm going to use one 1x6x4 board, one 2x2x8, a 3/4" dowel about 4 inches long, a 3" diameter hole saw, some glue, a saw, a hammer, nails, and some paint."
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Why does a Developer have a projects attribute and then a numberOfProjects attribute as well? Why does a Developer have a projects attribute at all?


These questions imply that there's something wrong with the decision to design a Developer with a projects and numberOfProjects attribute. Here are some more questions that will hopefully get you thinking about this some more and lead you to discover for yourself why these are poor design choices.

How long does a developer work on a project?
How often does the set of projects a developer works on change?
Is it only developers who work on projects? Are you going to create a ProjectManager class as well? A BusinessAnalyst class? A Tester class? Will these guys also have a projects attribute?
How are you going to see who all the people are involved in a particular project, regardless of their role? Is that going to be an easy thing to do with this design?

 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also have a look at the types of your variables. What is a set? Maybe you mean Set<Skill> or similar (if you are just beginning, that notation may be unfamiliar). Why are you using Strings for seniority when you could very easily write an enumerated type with seniorities ranging from DEAD_FLY_BEHIND_RADIATOR to CEO with some more sensible ranks in between. If you have a Set<Skill> or similar, that Set will have a size, so maybe you don't need a count of skills variable.
 
Philip Freeman
Ranch Hand
Posts: 31
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you thought provoking critique, it really helps. There is a need to change my way of thinking as well as the approach to the problem.
 
Philip Freeman
Ranch Hand
Posts: 31
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
providing*
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you add a Project to a Developer, or do you add a Developer to the Project? As well as add() methods, what about remove() methods because people don't work on a particular project for ever?
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic