Professional Documents
Culture Documents
Name Sec
Project 3 Questions
Instructions: Turn these answers in to the hw box. You must have these questions done by Project
3’s due date whether or not you have completed Project 3 on time. This will not be accepted late. We will
use a three point scale to grade every part of every question (e.g. 1a, 1b, 1c, and 1d). A 0 means either
that the answer is blank or that it isn’t even close. A 1 means it is minimally correct, but you could have
done better (we think you didn’t think it through very well.) A 2 means that it is satisfactory, but there is
room for improvement. A 3 means that it appears that you learned what you were supposed to learn and
you showed it to us. We hope and expect that you will get 3’s on each part. You get one point just for
turning it in for a total of 40 points.
Questions: Answers:
1. As you read the documentation you will
notice that for every class there is a domain
definition that is a logical or conceptual view
of the domain. Often the implementation
matches the conceptual point of view. For
instance, the conceptual definition for the
Token domain includes the three attributes:
type : TokenType
value : String
lineNumber : int
If you look at the source code you will see that
we implement the domain as:
protected TokenType type =
TokenType.UNDEFINED;
protected String value = null;
protected int lineNumber = -1;
At other times the domain definition is
significantly different from the
implementation. For instance, the domain
definition of Lex is:
tokens : Sequence<Token>
but the implementation is:
protected File file = null;
protected Token token = null;
In either case, we always include in a comment
the domain definition that matches the
conceptual view. Most students don’t include
a domain definition when they comment their
code. There is always a cost and a benefit to
providing domain definitions.
a) What is the cost?
b) What is the benefit?
c) Is the benefit worth the cost, why
don’t most students provide domain
definitions? If the benefit is not worth the
cost, explain why not.
2. The domain definition defines the data
structure of a class from an external point of
view. It defines what is wanted and imposes a
minimum set of constraints on the data
structure. By giving a definition, we can
determine if an implementation satisfies the
definition. For instance, the domain definition
of FactList is a set<Fact>. However, because
of inheritance, the domain is implemented as
ArrayList<Fact>. This could be a problem if
we allow the same fact to be added to
ArrayList twice.
a) In the code given, do we catch these
duplication errors?
b) Did we catch this during testing (look
at test/project3/FactListTest.java)?
c) Would you have even known there
was a problem without a domain
definition? (Why? Or why not?)
Two common solutions to this problem are to
(1) override the createList inherited from the
class List and make it check for duplicates, or
(2) change FactList so that it does not inherit
from DatalogSegment and implement the
domain as HashSet<Fact>.
d) Which would you choose and why?