Learning OOP, Love some input from you all

Hello everyone,

I had my interview and unfortunately I did not got picked but the director if the company was impressed of my will.
So basically I got a REAL simple assignment but it required OOP.
I made the test at my best and had the idea I could not change anything so it told them and we stopped.

Then I came home and got another bright idea what I had before.
So I recreated the assignment and tried to make it again at my best OOP.

So my question what can I improve ?
Here is the assignment : https://github.com/concept-core/person_oop

Best regards,
Wouter.

I would have used a model where two people are created and one chops off the others leg. Just setting the number of legs to one seems so uncreative.

Maybe so but this time it is not about being creative.
This was an assignment in a field where I have lite to no experience.
So being creative can come at a later time.

So my question to you, is this oop in a good way or meh oop ?
And yes I know it can always be better.

Well to be honest I think halt hat is a horrible way to tell whether someone knows oop. Having said that I can write up a quick something tomorrow to show you what I would of done.

Well I would appreciate it.
Please keep in mind I have no experience with oop.

There is some debate over whether or not getters and setters are best practice vs. public properties vs. magic __get __set

Hopefully any future potential employers that may test you this way aren’t biased one way or the other.

http://berryllium.nl/2011/02/getters-and-setters-evil-or-necessary-evil/

Hi Wouter,

I think it’s a really good idea to post at a forum and ask about the code you wrote :- ) That’s a good mindset to learn new things, I would think.

IMO the code makes too many assumption: it assumes that the person is going to have a name. That it needs a separate head field, but not fields for arms and legs?

The head field is an array, right? (I don’t know PHP but looks like an array.) That means it can have many heads?

Details like nose, mouth and ears shouldn’t be included, IMO, unless asked for.

I think: Add as little code as possible, nothing more than what you know for sure will be needed.

Two examples: (in Scala)

class Person { val bodyParts: List[BodyPart] }

+ some class/interface BodyPart { ... } I suppose. And to model a person with only one leg, exclude a leg from the List[BodyPart].

or: (this might be more like what they had in mind)

class Person {
  def head: Option[BodyPart]
  def body: Option[BodyPart]
  def leftArm: Option[BodyPart]
  def rightArm: Option[BodyPart]
  def leftLeg: Option[BodyPart]
  def rightLeg: Option[BodyPart]
}

and here you’d set e.g. leftLeg = None, instead of Some(aBodyPart)

It’s OK to include head and arms and legs I think, because they were mentioning a leg. But I think nose, mouth etc are too much details.

Best wishes with OOP and programming

Thanks for your reply.
Reason I made an array of the head is because they wanted to have a array returned with as much details of the person.

I know that maybe I should made a bit clearer.
Second it’s quite hard to understand oop because people all have the same mindset but often do things differently.

You said, I think: Add as little code as possible, nothing more than what you know for sure will be needed.

While some other people say, at least make sure you have all the variables needed for your object.

So I am not trying to say you are wrong and I am right but I am just asking why as little as possible?

With as little as possible, I mean that you should indeed add all the variables needed for your object. And nothing more :- )

I didn’t realize they actually did want the details. Then it makes sense I suppose, since they did ask for it

Usually in programming people add stuff they think will be needed later, it later turns out it wasn’t needed. Howerer all assumptions about what will be needed in the future, later on forces all code in the future to be built in a certain manner, and then, when the time comes to actually add new features, doing so is a lot harder, because of all assumptions made in the past.

Thanks for clarification, I will try to keep that in mind next time.

I would have thought a setBody() or setBodyParts() function would have made more sense than setHead() for setting the number of legs.

Scott

I will keep that in mind but for now it was ok.

Are there some good tutorials that explain oop from beginner to advanced?

I haven’t seen any single tutorial that goes from beginner to advanced in one go. That would be a lot to cover in one tutorial. There are quite a few for beginners, intermediate and advanced. Just google for them.

Scott

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.