Software Engineering & Object-Oriented Analysis & Design β Object-Oriented Fundamentals and Analysis, NEC licence examination syllabus (Nepal Engineering Council).
Adding Associations and Attributes
Connecting the concepts, and deciding what data belongs where.
π Where this lives: every multiplicity you write down is a business rule that will be enforced by a database constraint and defended by a validation error message. Get "an application has one applicant" wrong and years later someone will be filing a support ticket because a joint application cannot be entered. Associations look like decoration on a diagram; they are the assertions the entire system will be built to uphold. Search "cardinality business rule database constraint".
Associations
An ASSOCIATION is a relationship between conceptual classes
indicating a MEANINGFUL AND INTERESTING CONNECTION.
WHICH ASSOCIATIONS ARE WORTH RECORDING? Larman's guidance:
include those for which KNOWLEDGE OF THE RELATIONSHIP NEEDS TO
BE PRESERVED for some duration β the "need-to-know"
associations. Not every conceivable pairing.
THE COMMON ASSOCIATIONS LIST β a checklist analogous to the
concept category list, in rough priority order:
A is a PHYSICAL OR LOGICAL PART OF B
A is PHYSICALLY OR LOGICALLY CONTAINED IN B
A is a DESCRIPTION OF B
A is a LINE ITEM of a transaction B
A is KNOWN/LOGGED/RECORDED/CAPTURED in B
A is a MEMBER OF B
A is an ORGANISATIONAL SUBUNIT OF B
A USES OR MANAGES B
A COMMUNICATES WITH B
A is RELATED TO A TRANSACTION B
A is a TRANSACTION RELATED TO ANOTHER TRANSACTION B
A is NEXT TO B
A is OWNED BY B
A is an EVENT RELATED TO B
THE HIGH-PRIORITY ONES, worth applying first:
A is a part of B Β· A is contained in B Β· A is recorded in B
These three catch most of what matters in a business system.
NAMING AN ASSOCIATION: use a VERB PHRASE that makes the
relationship readable as a sentence, formatted
Class-VerbPhrase-Class.
Applicant βββ Submits βββΆ Application
Officer βββ Records βββΆ Payment
A diagram whose associations are unnamed forces every reader
to guess the meaning. "Application βββ District" could be
"belongs to", "was issued in", or "is valid in" β three
different rules.
MULTIPLICITY IS THE PART THAT MATTERS MOST. It states a
constraint that will be enforced, and it must be read in both
directions:
Applicant 1 ββββββ * Application
"one Applicant submits zero or more Applications"
"one Application is submitted by exactly one Applicant"
A CRITICAL SUBTLETY: MULTIPLICITY DEPENDS ON THE MOMENT you
ask, and on the scope of interest.
Is it "an Application has 0..1 Licence" or "1"?
β 0..1, because an application has no licence until issued.
Choosing 1 would forbid the entire pre-issuance
lifecycle.
Is it "a Counter has * Officers" or "0..1"?
β depends on whether you care about "who is at this counter
right now" (0..1) or "who has ever worked it" (*). ASK
WHAT QUESTION THE SYSTEM MUST ANSWER.
MULTIPLE ASSOCIATIONS BETWEEN THE SAME TWO CLASSES are
legitimate and often necessary:
Officer βββ Reviews βββΆ Application
Officer βββ Issues βββΆ Application
These are different relationships with different rules β a
reviewing officer and an issuing officer may be required to
be different people, which is a genuine control (separation
of duties). One association could not express that.
ROLE NAMES clarify each end where the class name is not enough:
Person [supervisor] βββ manages βββΆ [subordinate] Person
Self-associations require role names to be readable at all.
NAVIGABILITY (the arrowhead) is a DESIGN concern, not an
analysis one. In a conceptual model, leave associations
undirected β deciding which object holds a reference to which
is a visibility decision belonging to design (ACtE0805).
Attributes
An ATTRIBUTE is a logical data value of an object.
WHICH ATTRIBUTES TO INCLUDE: those for which the requirements
suggest or imply a need to REMEMBER INFORMATION. If no use case
needs it and no report shows it, it does not belong in this
iteration's model.
THE PRIMARY RULE, and it is worth stating as a rule because it
is broken constantly:
ATTRIBUTES SHOULD BE PURE DATA VALUES β
Boolean, Date, Number, String, Time, and domain-specific
simple types such as Money, PhoneNumber, PostalCode,
SocialSecurityNumber, ProductCode.
A RELATIONSHIP TO ANOTHER CONCEPT IS AN ASSOCIATION, NOT AN
ATTRIBUTE.
THE CLASSIC VIOLATION, and why it is wrong:
β Application
applicationNo : String
districtCode : String β this is a relationship
officerId : String β so is this
β Application ββ belongs to βββΆ 1 District
Application ββ issued by βββΆ 0..1 Officer
WHY IT MATTERS RATHER THAN BEING PEDANTRY:
Β· the foreign-key version HIDES the relationship, so the
diagram no longer shows the domain's structure
Β· it loses the MULTIPLICITY β a String cannot express
"exactly one" versus "zero or more"
Β· it imports a DATABASE IMPLEMENTATION TECHNIQUE into a
conceptual model, which is the "no design decisions"
discipline broken
Β· in code it produces `getDistrictCode()` followed by a
lookup, instead of `getDistrict()` β the
representational gap widening
DATA TYPE VERSUS CONCEPT β the judgement that decides whether
something is an attribute or a class of its own. Make it a
NON-PRIMITIVE CLASS (a value object) rather than a plain String
when:
Β· it is composed of SEPARATE SECTIONS β a phone number, a
person's name with title
Β· there are OPERATIONS associated with it, such as
validation β a citizen ID with a checksum
Β· it has other ATTRIBUTES β a promotional price with a
start and end date
Β· it is a QUANTITY WITH A UNIT β money with a currency,
which is the standard example
Β· it is an ABSTRACTION of one or more types with some of
these qualities β an item identifier
WORKED β why Money is not a Number:
amount : double β wrong twice over
(a) floating point cannot represent 0.01 exactly, so
repeated addition drifts; currency needs a decimal or
integer-minor-units representation
(b) a bare number carries no CURRENCY, so adding NPR to USD
is a compile-time-invisible error
money : Money { amount : Decimal, currency : Currency }
β now `add` can refuse mismatched currencies, and the
rounding rule lives in one place. THE TYPE PREVENTS A
CLASS OF DEFECT, which is the argument for value objects
generally.
DERIVED ATTRIBUTES, marked with a leading /:
Application
appliedOn : Date
/ age : int (computed from appliedOn)
/ feeDue : Money (computed from District.feeRate
and the licence category)
RECORDING SOMETHING AS DERIVED IS A REAL DECISION: it says
the value must never be stored independently, which prevents
the defect of a stored total disagreeing with its inputs. If
the derivation is expensive it may be CACHED in design β but
that is a design decision, made later, and the model still
records that it is logically derived.
ATTRIBUTES THAT DO NOT BELONG IN A CONCEPTUAL MODEL:
Β· foreign keys and surrogate identifiers, per the rule
above β unless the identifier is a real-world one the
domain uses, like a licence number, which IS a legitimate
attribute
Β· `createdAt` / `updatedAt` audit columns, unless the domain
genuinely asks about them
Β· flags that duplicate derivable information β
`isPaid : Boolean` when the presence of a Payment
association already says it. Duplicated state is state
that can disagree with itself.
Worked: refining a model with the domain expert
A FIRST-CUT MODEL, then the questions that fix it. The questions
are the technique.
FIRST CUT, drawn from the use cases alone:
Applicant Application
- citizenId : String 1 * - applicationNo : String
- fullName : String ββββββ - appliedOn : Date
- districtCode : String - status : String
- fee : double
- officerId : String
- isPaid : boolean
THE INTERROGATION β six questions and what each changed:
Q1 "Can one application have two applicants β a joint
application for a company vehicle?"
A: yes, for commercial licences.
β multiplicity changes from 1 to 1..*, and this is a
substantial change: every screen, query and validation
assuming a single applicant is affected. FOUND IN A
CONVERSATION rather than in integration testing.
Q2 "Is districtCode the applicant's home district or the office
where they applied?"
A: they can differ β you may apply anywhere.
β TWO separate associations were hiding inside one
attribute:
Applicant ββ resides in βββΆ 1 District
Application ββ lodged at βββΆ 1 DistrictOffice
This is exactly the failure the foreign-key rule predicts:
an attribute concealed a relationship, and concealed that
there were two of them.
Q3 "Is status just a value, or do you need its history?"
A: an auditor must see every change with who and when.
β status remains an attribute (the current value) AND a new
concept appears:
Application βββ * StatusChange
- from, to : Status
- changedOn : Instant
- changedBy : Officer
Q4 "Is the fee always the same for a given category?"
A: it varies by district, and the rates changed in July.
β `fee : double` was wrong three times: it is Money not
double; it is derived not stored; and the rate is
EFFECTIVE-DATED:
FeeRate
- category, district
- amount : Money
- validFrom, validTo : Date
Application./feeDue is derived from the FeeRate in force
ON THE APPLICATION DATE β not the current rate, which
would silently reprice historical applications. This is
the "modelling time as an afterthought" trap, caught.
Q5 "Which officer is officerId β who reviewed it or who issued
it?"
A: they must be different people.
β two associations, and a CONSTRAINT worth writing on the
diagram:
{reviewedBy β issuedBy}
A separation-of-duties control, now visible in the model
instead of buried in code.
Q6 "What does isPaid mean if a payment was refunded?"
A: it should reflect the current settled state.
β the flag is DELETED. It duplicates information already
present in the Payment association, and the refund case
proves the two can disagree. `/ isPaid` becomes derived,
or the question is answered by asking the payments.
THE REFINED MODEL:
Applicant Application
- citizenId : CitizenId 1..* * - applicationNo
- fullName : PersonName βββββββ - appliedOn : Date
β - status : Status
β resides in / feeDue : Money
βΌ 1 / isPaid : Boolean
District β
β² 1 β *
β lodged at StatusChange
DistrictOffice βββββ 1 * ββββ Application
Application ββ reviewedBy βββΆ 0..1 Officer
Application ββ issuedBy βββΆ 0..1 Officer
{reviewedBy β issuedBy}
FeeRate - category, district, amount, validFrom, validTo
COUNT THE OUTCOME: 6 questions changed 1 multiplicity, split
1 attribute into 2 associations, added 2 concepts, deleted
1 attribute, corrected 1 data type, and surfaced 1 business
constraint. NONE OF IT REQUIRED CODE, AND ALL OF IT WOULD
OTHERWISE HAVE BEEN FOUND DURING TESTING OR AFTER RELEASE.
That ratio is the argument for conceptual modelling.
Question 4 is the one worth studying. fee : double was wrong in three independent ways at once β wrong type (floating point for money), wrong storage (stored rather than derived), and wrong in time (a single rate where the domain has effective-dated rates). A single innocuous-looking attribute can conceal three distinct defects, and only a question to the domain expert finds them.
π Go further: the money problem in Q4 has a formal name β value objects β and a general principle behind it: make illegal states unrepresentable. If Money carries its currency and refuses to add mismatched currencies, currency-mixing bugs cannot compile rather than being caught by a test. Applied widely (an EmailAddress type that cannot hold an invalid string, a NonEmptyList, a PositiveQuantity) it moves whole categories of defect from run time to compile time, which is the cheapest place to catch anything. Search "make illegal states unrepresentable value objects".
π‘ Exam angle: define association and attribute, and state the need-to-know criterion for including an association. Know the common associations list, especially the high-priority "is a part of / is contained in / is recorded in". Be able to read and write multiplicity in both directions, and name association ends with a verb phrase. The most examined rule is that attributes must be pure data values and a relationship to another concept is an association, not an attribute β be ready to correct a model containing foreign-key attributes. Know the criteria for making an attribute a non-primitive class (sections, operations, its own attributes, a quantity with a unit) and what a derived attribute (/) asserts.
Syllabus points
Associations, multiplicity, attributes
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Related topics in Object-Oriented Fundamentals and Analysis