Tina Comston Comp-111 Week 11 Franklin University |
||||
Week 11 | ||||
Preparation
|
||||
Guided
Learning Activity |
||||
Assignment
- no homework assignment this week Class Types Up to this point in
the course, we have been dealing with domain classes. These
are the user-defined data type we have been writing for the homework
assignments and labs. In addition to domain classes, there
are also actors, utility, and library classes.
Domain Class - typically thought of as a noun, for example employee or time card. Each class represents a single concept. Actor Class - models a verb or action, usually a process. These types of classes do things to or for the domain class, but don't have any instance variables unique for each object. For example FederalTaxCalculator. Typically these classes have names that end in er or or. Utility Class - provide reusable services for both domain and actor classes. For example the Math class. Library Class - groups of reusable components that are used to assemble a program. For example the ArrayList or Scanner classes. Cohesion & Coupling Cohesion - the degree to which a class models a single concept. For
example student class - it might contain a name, date of birth,
address, gpa, and so on. This would be an example of low
cohesion - there are too many concepts in this class. Instead, the date of birth could be broken out to be a date object, where the date object has all of the methods associated with the date itself, such as calculating the age. The address could be broken out to be an address object and then could be used for primary address, campus address, emergency contact address, etc. This could then contain methods to format the address with city, st zip format, verify the state is a correct abbreviation, etc. The gpa could be broken out to be a gpa object which would contain methods related to this component. With all of these items become their own classes and representing a single concept, we now have high-cohesion, which is the goal. Coupling - how much a class depends on other classes to work properly. The more a class depends upon another class, the more challenging it is to develop, test, and maintain the class. Low coupling is the goal. YouTube video on coupling and cohesion https://www.youtube.com/watch?v=ZND1JAJIofA Another video on coupling and cohesion with a couple of great examples https://www.youtube.com/watch?v=Ujq_xsd-9MQ Pre-Condition and Post-Condition Pre-Condition
- any requirement that must be met for a method to function correctly.
For example, a valid date or valid number. Post-Condition - the value that is returned by the method or the final state of the object and it's instance variables. We have been testing post-conditions with our junit test cases. |
||||
Exam
2
|
||||
Reflection
Paper
|
||||
Lab 4
|