• 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

How should i design my classes for an application?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, could you give me some advice?

I am working on the following project:

A website where teachers can post lessons and students can follow them. So I decided to begin by building some classes:

I will make a class for User (with username, email address, birthday..) and because I understand it is best to choose composition over inheritance and because some students can later become teachers, I am thinking to make User to have-a Position.

Then Position will be the super class of Student and of Teacher. Now I want to make a connection between the Student/Teacher and the lessons.

For example, one of the things I want is a teacher to have lessons that he posted himself, but also lessons that other posted and where he is only mentoring his students. I would like the teacher to log on and be able to see a list of his lessons (his or where he is mentor) and then to click on a lesson and see the students and their progress.

It is just not very clear how to connect the teacher to his lessons. I was thinking to make the Teacher have an ArrayList of Lesson objects, but somehow it feels wrong. Is it?

Please give me a clue on how to proceed. I am stuck and I am feeling really stupid right now .

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Composition is not necessarily better than inheritance. It depends on the situation.

When you mention position, this is considered an attribute of the User class/object. So Student and Teacher inherit User.

Lessons are something students take and teachers teach. So Students/ Teachers have (collection of) Lessons (example of composition)

Since students can become teachers later, I suggest you use an interface with method say teach(Set<Lesson>) so students can implement. Using such approach, that position attribute in the User class will have no purpose.

Now the question is when do students become eligible to teach? Is it based on courses they took or number of credits before graduation or something else? A flag in the Student class may be more appropriate then "position" in User. By default, Teachers always can teach.

The mentor status for Teacher can use the similar approach above as Student can teach status.

Hope this helps a bit.
 
Casandra justina
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much! It does help, I know now what I have to correct and how to proceed
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're falling into what I will start to call the "Starting with the Nuts and Bolts" trap. Or maybe it should be called the "Solution looking for a Problem" trap. Object orientation is not so much about modeling objects in the real world as it is about assigning the responsibility of doing something to the correct abstraction. A program "object" is an abstraction and its methods carry out the object's responsibilities. Any information encapsulated in the object should be there to support its ability to carry out its responsibilities.

Let's take this for example:

A website where teachers can post lessons and students can follow them


Just because this statement mentions teachers and students, it doesn't necessarily mean that you will have these abstracted as objects in your program. Sure, a (real-world) teacher will use the program but what will the Teacher object do? If you start programming by writing a Teacher class without really knowing what its purpose is, then all you've succeeded in doing was to create a "solution" to an undefined "problem".

A better way is to start with high level stories of what your program will do to satisfy its users' needs.

Start with this story/scenario: "As a Teacher, I would like to post a lesson so that my students can start going through it."

Now you can identify your user, a teacher, and what they want to do: post a lesson. How does a teacher post a lesson? What form would that lesson be in that they can enter it into a computer? How is this lesson going to be stored in the computer?

Then you can have another story/scenario: "As a student, I want to view a lesson that my teacher posted so that I can go through it and learn the material."

How does the student select a lesson? How is the lesson presented to the student? How do they show that they have gone through a lesson? How are they rated/tested on their understanding of the material in the lesson? Should these last two even be considered as part of this scenario or should we have another scenario to cover them. Like, "As a student, I'd like to be tested on my understanding of the material in a lesson so that I can be graded by my teacher" or something like that.

Another analogy to this is that of producing a movie or a play. You don't just start with a bunch of random characters and start giving them costumes and lines to deliver. You first think of a plot. The plot will give you a general story line. Then, you develop detailed story lines that support the main story line. When you have these story lines, you'll have a better idea of who the characters are who will play roles in them. Once you have that, then you can develop the characters and give them personalities, traits, actions, interactions, and dialog. Objects are like that: they are the characters in the story that is your program.

Does that make sense?
 
Casandra justina
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much! After spending a few hours drawing classes over and over, I do understand the trap you are talking about.
I started to make a list of everything a student can do from the moment he enters the website and same for the teacher and it starts to look better now.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic