CIS 320 Final Chapter 8
What are constraints? What are the three different types of constraints?
Constraints are limitations on the range of values or activities that are acceptable within the business problem domain. The three types are pre-conditions, post-conditions, and invariants.
What is dynamic binding?
Dynamic binding refers to the ability of an object-oriented system to defer the data typing of objects until run time. This would allow a message such as compute employee pay to be interpreted differently at run time by 'salaried employee" and "hourly employee" objects. This feature is language dependent and must be implemented differently depending on the language in which the system is to be programmed.
How are factoring and normalization used in designing an object system?
Factoring is the process of separating out aspects of a method or class into a new method or class to simplify the overall design. Normalization is a technique borrowed from relational database design aimed at helping to identify new classes and insure that all attributes are dependent on their assigned classes and only on their assigned classes.
What are the seven types of method cohesion? Give one example of "good" method cohesion and one example of "bad" method cohesion?
Functional, sequential, communicational, procedural, temporal or classical, logical, and coincidental. An example of a good method cohesion is functional where an object "calculate totals" may keep a running total of the quantity times price subtotal for each item. An example of a relatively bad method cohesion would be unrelated activities in the same method. For example, a method that updates customer records, calculates loan payments, prints exception reports, and analyzes competitor pricing structures wouldn't display good cohesion.
What additional types of inheritance conflicts are there when using multiple inheritances?
In addition to conflicts between superclasses and subclasses, one would now have the possibility of conflict between the superclasses. Three additional conflicts specifically are: a) Two inherited attributes (or methods) have the same name and semantics. b) Two inherited attributes (or methods) have different names but with identical semantics; that is they are synonyms. c) Two inherited attributes (or methods) have the same name but with different semantics; that is, they are homonyms. This also violates the proper use of polymorphism.
What is inheritance conflict? How does an inheritance conflict affect the design?
Inheritance conflict occurs when the name of an attribute or method of a class has the same as an attribute or method of a superclass. It creates complexity in updates since changes in the attributes or methods at one level will affect those at another level.
What is an invariant? How are invariants modeled in a design of a class? Give an example of an invariant for an hourly employee class.
Invariants model constraints that must always be true for all instances of a class. We attach invariants to the CRC cards or class diagram by adding a set of assertions. Employee ID (1..1) (unsigned long) {Employee ID = Employee, Get Employee ID()}
How important is it to know which object-oriented programming language is going to be used to implement the system?
It is critical because each language enacts critical object-oriented design elements differently. Properly utilizing the specific language to implement these concepts is critical to successfully creating robust application programs.
Create a contract for a "compute-pay" method associated with an hourly employee class.
Method name: "compute-pay" Class name: "hourly employee" ID: 1 Clients: Hourly employee, perhaps salaried employee Associated Use Cases: Paying the employees Description of Responsibilities: Accept the hours, pay rate, and related information. Perform the math needed to return the total pay for the individual employee. Arguments received: Hours, pay rate, deductions Type of value returned: Gross wage, Net wage Pre-conditions: Hours must be within preset range (generally 0-40; overtime may be calculated over 40 hours or an investigation setup) Post-conditions: None.
What are the five types of connascence described in your text? Give one example of each type.
Name, Type or class, Convention, Algorithm, and Position. Name connascence refers to a situation where a method references an attribute. As a result, if the name of the attribute changes, the coding of the method must also change. If the method is "Get product number" where product number is an attribute of "product" class, then if the product class changes the name of the attribute from product number to product code (perhaps there are now alphanumeric as well as numeric named products), then the method must change. Type or class connascence refers to the relationship between attributes and the data type to which it is assigned. If, for example, the programmers choose to use a "date" data type to indicate the date, rather than some other data type formulation, they will have to change the class if they want to change the data type. Convention connascence refers to situations where the values of an attribute are assigned semantic meaning -- in other words are used more as a code than to mean exactly what they designate. Should the range of values be changed, then all the methods that use that attribute would also need to change. Algorithm connascence refers to situations where multiple methods of a class are dependent on a particular algorithm. In a hashing situation, where an algorithm determines the location of a particular record, then both insert a record and find a record would need to be changed if the algorithm determining the location were to change. Position connascence refers to the order of code in a method or the order of arguments being critical for correct execution. For example, if the record must be found before being modified, the order of actions is critical for correct functioning. This situation can raise very subtle semantic difficulties in mathematical operations that sequence sensitive like making averages from subtotals versus from the entire data set.
What are the six types of interaction coupling? Give one example of "good" interaction coupling and one example of "bad" interaction coupling?
No direct coupling; data coupling, stamp coupling, control coupling, common or global coupling, and content or pathological coupling. An example of a good use of coupling would be for an object to pass the value of a variable along with a message. For example, the object "invoice" could send to "calculate tax" the taxable amount. An example of relatively bad coupling would occur where a global data area exists outside the objects. For example a table of user preferences may simply be available for access and change by a variety of objects. This is a situation that occurs normally in COBOL. Under adverse circumstances, a program can expect the same numbers that were stored at the end of one run to be present at the beginning of the next run; but in the meantime other programs may have changed that value.
What are patterns, frameworks, class libraries, and components? How are they used to enhance the evolving design of the system?
Patterns are combinations of elements that are found in multiple locations. For example, any business situation updating a master file will have some common procedures for examining the transaction files and changing the status of the master file. These repeating situations allow the reuse of design structures saving time and effort for the project members. Patterns frequently need to be customized for a particular application, so they should be carefully reviewed rather than being mindlessly copied. Frameworks are a set of implemented classes that can be used as a basis for implementing an application. These can be used to aid in object persistence and creating inheritance. When the framework changes, the program needs, at a minimum, to be recompiled and probably needs to be updated if there are any changes in dependencies. Class libraries consist of sets of implemented classes and are designed for reuse. These are similar to frameworks, other than that frameworks tend to be domain specific. Frameworks may, in fact, be built using class libraries. Components are self-contained encapsulated pieces of software that can be "plugged" into a system to provide a specific set of required functionality. Each of these approaches is used to streamline the development process by allowing work already completed to be added to the current project.
Define polymorphism. Give one example of a "good" use of polymorphism and one example of a "bad" use of polymorphism.
Polymorphism means having the ability to take on multiple forms. It is used in the object oriented world to refer to the ability for a message to be sent to different objects that will process it in different ways. An example of good polymorphism would be sending the message "print document" to a 'laser printer" or an "ink-jet" printer and having each printer perform its own operations to enact printing the document. An example of "bad" polymorphism would be "create order" which would mean start the sales process in a marketing system but might mean straighten up the living room in a housekeeping system.
How do you specify a method's algorithm? Give an example of an algorithm specification for a "compute-pay" method associated with an hourly employee class using structured english.
Specific algorithms will vary, but should include recognition of some check for hourly employment, some calculation of gross pay, some calculation of net pay, some printing of check. Students may also add in year-to-date information, which is on most pay statements. FOR all Employees in Employee Object Store IF Employee Status = "hourly" THEN Perform range check for "hours worked" Gross wage = "hours worked" * "pay rate" Accumulated payroll = accumulated payroll + gross wage Perform calculate taxes Perform sum deductions Net wage = gross wage - deductions Save totals to Payroll Object Store Print pay statement (gross wage, all deductions, net wage) ELSE Continue to next Employee Object ENDIF
What is the Object Constraint Language? What is its purpose? (Page 345).
The Object Constraint Language (OCL) is a complete language designed to specify constraints. Essentially, all OCL expressions are simply a declarative statement that evaluates to either being true or false. If the expression evaluates to true, then the constraint has been satisfied. OCL also has the ability to: • traverse relationships between objects • model more-complex constraints with a set of logical operators: and, or, xor, and not OCL provides: • many other constructs that can be used to build unique constraints. These include math-oriented operators, string operators, and relationship traversal operators. • a set of operations that are used to support constraints over a collection of objects. • a rich set of operators and operations in which to model constraints. Obviously, OCL provides a rich set of operators and operations in which to model constraints.
What are the basic characteristics of object-oriented systems?
The basic characteristics of object-oriented systems are: Classes, objects, methods, and messages. The object is a basic unit that operates in the object-oriented world. Objects are created from classes which act as templates; they contain the ability to take action in the form of methods and they send and receive messages to and from other objects. Encapsulation: Objects are encapsulated so that they share only the elements that are relevant to other objects and hide their own data stores and methods when not relevant to other elements. Polymorphism allows an object to send the same message to a variety of objects, which may interpret and take action differently on the same message based on differences in their own logic. Inheritance allows developers to define classes that are related through common elements but that differ in other substantial ways. This makes it simpler to define classes.
What is the typical downside of system optimization?
The design before optimization is generally aimed at understandability. After optimization, the design is likely to perform better, but the linkage to the problem and user domain is likely to be somewhat more obscure and difficult to explain.
What is the Law of Demeter?
The law minimizes the number of objects that can receive messages from a given object. The law states that an object should only send messages to itself, to an object that is contained in an attribute of the object (or one of its superclasses), to an object that is passed as a parameter to the method, an object that is created by the method, or to an object that is stored in a global variable.
Why is cancellation of methods a bad thing?
The purpose of the inheritance and classification of the classes and subclasses is to streamline and clarify the genuine underlying relationship amongst them. When an inherited method is cancelled, it indicates that some design flaw has been patched. This can present future problems and indicates that the design may have included flaws.
How are methods specified? Give an example of a method specification for a compute-pay method associated with an hourly employee class.
There is no formal syntax; however, Figure 14-11 provides a nice format. Student should expand the information presented in question 23 adding information such as programmer, date due, programming language. Triggers/Events: should indicate a time period such as weekly, bi-weekly, semi-monthly, monthly, or some other reasonable period. Algorithm specification should make use of the answer to question 24.
What are exceptions?
Violations of a constraint are known as exceptions in languages such as Java and C++.
When designing a specific class, what types of additional specification for a class could be necessary?
a) Ensure that the classes on the problem domain layer are both necessary and sufficient to solve the underlying problem. b) Finalize the visibility of the attributes and methods in each class. c) Decide on the signature of each method in every class. d) Define any constraints that must be preserved by the objects, for example that values must exist only within a specific range as well as the response should constraints be violated. For example, if employees are only allowed to work up to "60" hours per week and someone attempts to enter "61" for the attribute hours worked, what response should be taken by the system?
What are the four types of class cohesion? Give one example of each type.
a) Ideal class cohesion, where all methods and attributes clearly relate to the same entity such as an employee, department, or an order. b) Mixed-role cohesion, where the class has one or more attributes that relate to other objects on the same layer. An example might be where a "student" class also contains instance of courses that students might be taking. c) Mixed-domain cohesion, where the class has one or more attributes that relate to other objects on different layers. An example might be where a data layer object refers to specific icon objects on the presentation layer. d) Mixed-instance cohesion, where, the class represents two different types of objects which should be split into separate classes. For example if "student" and "class enrollment" information were combined in a single class.\
Give the guidelines to avoid problems with inheritance conflicts.
a) Query operations should not be redefined. b) Methods that redefine inherited ones should only restrict the semantics of the inherited ones. c) The underlying semantics of the inherited method should never be changed. d) The signature (argument list) of the inherited method should never be changed.
What are the different ways to optimize an object system?
a) Review the access paths between objects. b) Review the attributes of each class. c) Review the direct and indirect fan-out of each method. d) Look at execution order of the statements in often-used methods. e) Avoid re-computation by creating derived attributes.
What is the purpose of a contract? How is it used?
A contract formalizes the interactions between client and server. The client object sends a message to the server object which guarantees, given that all constraints are met, the return of the response to the request.
How do you specify a method's algorithm? Give an example of an algorithm specification for a compute pay method associated with an hourly employee class using an activity diagram.
A method specification is a written document that provides clear and explicit instructions on how a method is to behave. Without clear and unambiguous method specifications, critical design decisions have to be made by programmers instead of by designers. Even though there is no standard format for a method specification, typically four types of information are captured. • First, there is general information such as the name of the method, name of the class, contract ID, programmer assigned, the date due, and the target programming language. • Second, owing to the rise in popularity of GUI-based and event-driven systems, events also are captured. • Third, the information that deals with the signature of the method, data received, data passed on to other methods, and data returned by the method is recorded. • Finally, an unambiguous specification of the algorithm is given. The algorithm typically is modeled using Structured English, an activity diagram, or a formal language. (Page 363). Finally, if the methods are not semantically consistent, the developer cannot assume that all methods with the same name will perform the same generic operation. For example, imagine that you have an array of type person that contains instances of employees and customers
What is the Structured English? What is its purpose? (Page 356)
Algorithm specifications can be written in Structured English or some type of formal language. Structured English is simply a formal way of writing instructions that describe the steps of a process. Because it is the first step toward the implementation of the method, it looks much like a simple programming language. Structured English uses short sentences that clearly describe exactly what work is performed on what data. There are many versions of Structured English because there are no formal standards; each organization has its own type of Structured English. Figure 8-27 shows some examples of commonly used Structured English statements. Common Statements: • Action Statement- Simple statements that perform some action • If Statement- controls actions that are performed under different conditions • For Statement-(or While Statement) performs some actions until some condition is reached • Case Statement- an advanced form of an If statement that has several mutually exclusive branches