|
5 years ago | |
---|---|---|
.idea | 5 years ago | |
demo | 5 years ago | |
README.md | 6 years ago |
Classroom
bean which mediates a composite Students
and Instructors
bean reference.AnnotationConfigApplicationContext
@Bean
@DependsOn
@Autowired
@PostConstruct
@Config
@SpringBootTest
@Qualifier
Part 0.0
@Configuration
scans from current directory down.Part 10
, this project is nearly identical to the LearnerLab
completed in the past.Search for Dependencies
input box search for
DevTools
Web
Generate Project
demo
project generated by start.spring.io
, into the newly cloned learnerlab
folder.pom.xml
from IntelliJ > File > Open
Open as Project
when promptedPerson
ClassPerson
class.
final
field named id
of type long
.name
of type String
.Person
constructor should have a parameter of type Long id, String name
which sets each of the fields to their respective value.getId()
method which returns the Person
object's id
field.getName()
method which returns the Person
object's name
field.setName()
method which sets the Person
object's name
field.-
Learner
InterfaceLearner
interface.
Learner
should declare one method signature:
learn
double numberOfHours
void
-
Student
ClassStudent
class such that:
Student
is a subclass of Person
Student
implements the Learner
interfaceStudent
should have an instance variable totalStudyTime
of type double
Student
should have a concrete implementation of the learn
method which increments the totalStudyTime
variable by the specified numberOfHours
argument.Student
should have a getTotalStudyTime()
method which returns the totalStudyTime
instance variable.-
Teacher
InterfaceCreate a Teacher
interface.
Teacher
should declare a teach
method signature:
teach
Learner learner
double numberOfHours
void
Teacher
should declare a lecture
method signature:
lecture
Iterable<? extends Learner> learners
double numberOfHours
void
-
Instructor
ClassInstructor
class such that:
Instructor
is a subclass of Person
Instructor
implements the Teacher
interfaceInstructor
should have a concrete implementation of the teach
method which invokes the learn
method on the specified Learner
object.Instructor
should have a concrete implementation of the lecture
method which invokes the learn
method on each of the elements in the specified array of Learner
objects.
numberOfHours
should be evenly split amongst the learners.
double numberOfHoursPerLearner = numberOfHours / learners.length;
People
People
class
PersonType
such that PersonType
is a sub class of Person
.Iterable
of type PersonType
.People
should consume a List
of PersonType
and set it to a respective personList
field.PersonType
objects and sets the personList
field respectively.add
which adds a PersonType
to the personList
.remove
which removes a PersonType
from the personList
.size
which returns the size of personList
.clear
which clears our personList
field.addAll
which adds an Iterable
of PersonType
objects to the composite personList
.
Collection<PersonType>
findById
which makes use of a long id
parameter to return a PersonType
object with the respective id
field.findAll
which returns the composite personList
.-
Students
Students
class.
People
of parameterized type Student
.Student
objects upon construction and pass them to the super constructor.-
Instructors
Instructors
class.
People
of parameterized type Instructor
.Instructor
objects upon construction and pass them to the super constructor.-
Classroom
Classroom
class.
Instructors
and Students
object upon constructionhostLecture
which makes use of a Teacher teacher, double numberOfHours
parameter to host a lecture
to the composite personList
field in the students
reference.
-
Configuration
classesConfig
classes should have a class-signature annotation of @Configuration
@Bean
definitions within the scope of the class, and register them to the IOC Container for Inject
and Autowire
use later.@Autowired
@Autowired
does not know which beans to use for injection.@Qualifier
@Autowired
, clarifies which beans to be wired by specifying the bean name (wired by name)-
StudentConfig
currentStudents()
which returns a Students
representative of the current cohort of students.
@Bean(name = "students")
@Bean
whose name
attribute is not specified defaults to the name of the method it is annotating.previousStudents()
which returns a Students
representative of the previous cohort of students.-
InstructorsConfig
tcUsaInstructors()
which returns an Instructors
representative of the Tech Connect USA instructors.tcUkInstructors()
which returns an Instructors
representative of the Tech Connect UK instructors.instructors
which returns all Instructors
employed at ZipCodeWilmington
@Primary
Autowire
annotation is not supplied with a Qualifier
annotation-
ClassroomConfig
currentCohort()
which returns a Classroom
object whose dependencies are instructors
and students
previousCohort()
which returns an Classroom
object whose dependencies are instructors
and previousStudents
@DependsOn
annotation to help the Spring framework and other readers of the code to understand what order beans should be executed.
@DependsOn({"instructors", "students"})
-
Config
classesTest
classes should be annotated with
@RunWith(SpringRunner.class)
junit
should use to run tests@SpringBootTest
ContextConfiguration
that tells the test class how to load the ApplicationContext
.ContextConfiguration
classes are specified as a parameter to the @SpringBootTest
annotation, the default behavior is to load the ApplicationContext
by scanning for a @SpringBootConfiguration
annotation on a class in the package root.@Autowired
along with @Qualifier(name = "beanname")
-
StudentConfig
ClassTestStudentConfig
class in the test
package.Bean
in the StudentConfig
class is configured as expected.toString
method to get a representation of the aggregate state of any People
object.-
InstructorConfig
ClassTestInstructorConfig
class in the test
package.Bean
in the TestInstructorConfig
class is configured as expected.-
ClassroomConfig
ClassTestClassroomConfig
class in the test
package.Bean
in the TestClassroomConfig
class is configured as expected.@Component
@Component
allows Spring to register the class as a Bean
implicitly.-
Alumni
ClassAlumni
component which autowires Students
of the previous cohort and Instructors
executeBootcamp
method which teaches each Student
in the composite Students
a totalNumberOfHours
of 1200
.
@PostConstruct
-
Alumni
ClassStudent
in the Alumni
class has been taught 1200
hours upon injection of the Alumni
dependency.Ensure the numberOfHoursTaught
has been evenly distributed amongst each of the instructors.
Tip: How to derive numberOfHoursTaught
dynamically
int numberOfInstructors = instructors.size();
int numberOfStudents = students.size();
double numberOfHoursToTeachEachStudent = 1200;
double numberOfHoursToTeach = numberOfHoursToTeachEachStudent * numberOfStudents;
double numberOfHoursPerInstructor = numberOfHoursToTeach / numberOfInstructors;