Hi everyone
I'm coding a grade book. Doing so I wondered what you would code in your real life projects. I've coded several solutions. Each having advantages and disadvantages. Please elaborate your answer. Or even come up with a better solution
In this first solution course contains the grades. This seems wrong though. If course were to be an object one would expect a dictionary linking the pupils of the course to their grades. As such one would get an n-to-n relation (a student has several courses, a course has several students). Adding a grade would require the developer to iterate through the entire gradeBook array.
This solution wouldn't run yet because I would have to render Course equable and hashable. But once more I have my doubts. When I would have to add a grade it would be really messy to enter that Course instance as key. Further more I'm in doubt if a grade book isn't directly correlated to a course instance.
The problem I have with it is that the title of a course object would be the same as the key in the gradeBooks property of pupil.
In this approach one would have to iterate over all grade books to get the right one. Changing it is easy.
Please share your vision! Tx
I'm coding a grade book. Doing so I wondered what you would code in your real life projects. I've coded several solutions. Each having advantages and disadvantages. Please elaborate your answer. Or even come up with a better solution
Code:
struct Name {
var firstName: String
var lastName: String
}
struct Course {
var title = ""
var lectureMoments: Int
var gradeBook: GradeBook
}
struct Pupil {
let name: Name
var courses: [Course]
}
struct GradeBook {
var grades: [Int] = []
}
In this first solution course contains the grades. This seems wrong though. If course were to be an object one would expect a dictionary linking the pupils of the course to their grades. As such one would get an n-to-n relation (a student has several courses, a course has several students). Adding a grade would require the developer to iterate through the entire gradeBook array.
Code:
struct Name {
var firstName: String
var lastName: String
}
struct Course {
var title = ""
var lectureMoments: Int
}
struct Pupil {
let name: Name
var gradesPerCourse: [Course: GradeBook]
}
struct GradeBook {
var grades: [Int] = []
}
Code:
struct Name {
var firstName: String
var lastName: String
}
struct Course {
var title = ""
var lectureMoments: Int
}
struct Pupil {
let name: Name
var gradesPerCourse: [String: GradeBook]
}
struct GradeBook {
let course: Course
var grades: [Int] = []
}
Code:
struct Name {
var firstName: String
var lastName: String
}
struct Course {
var title: String
var lectureMoments: Int
}
struct Pupil {
let name: Name
}
struct GradeBook {
let course: Course
let pupil: Pupil
var grades: [Int] = []
}
Please share your vision! Tx