Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 39 ยท Projects and Practice

UML Interview Questions

Common UML and software modeling interview questions with clear answers: diagram types, relationships, state machines, components, OCL and modeling in practice.

Interviewers rarely ask you to recite the specification. They want to know whether you can use UML to think and to communicate: choose a diagram, read one, spot a flaw, and relate it to code. This page collects frequent questions with concise answers. Say the answers in your own words, add an example from a project you did, and be ready to sketch on a whiteboard.

Basics

What is UML and why use it? The Unified Modeling Language is a standard visual language to specify, visualize and document software systems. Use it to communicate designs, to think through a problem before coding and to document decisions. It is notation, not a process.

Name the two families of diagrams. Structure diagrams (class, object, component, composite structure, deployment, package, profile) and behavior diagrams (use case, activity, state machine, and the interaction diagrams: sequence, communication, timing, interaction overview).

When would you not use UML? For trivial code, for a design that changes daily, and when a short conversation or a code sketch is faster. Never produce diagrams only to satisfy a process.

Class diagrams

Explain association, aggregation and composition. Association: a general link between classes. Aggregation: a whole-part relationship where the part can exist alone. Composition: strong ownership; parts live and die with the whole, and a part belongs to only one whole.

Inheritance versus interface realization? Generalization shares behavior and structure from a superclass (solid line, hollow triangle). Realization means a class promises to provide the operations of an interface (dashed line, hollow triangle). Prefer interfaces and composition for flexibility.

What is the difference between dependency and association? A dependency is temporary use (parameter, local variable); an association is a structural relationship stored as a field.

What does multiplicity express? How many instances can take part in a relationship, such as 1, 0..1, 1..*, *. It becomes a constraint in code and in the database.

Behavior diagrams

Sequence versus communication diagram? Both show interaction. A sequence diagram emphasizes the order of messages in time; a communication diagram emphasizes the links between objects. They carry the same information.

Use case versus activity diagram? A use case diagram shows what actors want (goals); an activity diagram shows how a process flows, with decisions and parallel steps.

What are include and extend in use cases? include: a base use case always calls another (shared behavior). extend: optional behavior added to a base use case under a condition.

What is a guard? A boolean condition in square brackets that must be true for a transition or branch to be taken.

State machines

What does a transition label contain? event [guard] / action, all parts optional.

What is a composite state, and why use it? A state containing substates. Transitions drawn at its boundary apply to all substates, so you avoid duplicating arrows. Orthogonal regions model parallel parts.

What is a history state? A pseudostate that lets a composite state resume its last active substate (shallow) or its full nested configuration (deep) when it is re-entered.

What happens to an event with no matching transition? It is discarded; the object stays in its state.

How do you implement a state machine? With nested conditionals for small ones, a transition table for data-driven ones, the State pattern for rich per-state behavior, or a library for hierarchical and concurrent machines.

Architecture

What is a component? A modular, replaceable part that hides its contents behind provided and required interfaces.

Component versus package? A package is a namespace to organize model elements, with no run-time meaning. A component is a unit with interfaces that can be built, replaced and deployed.

What does a deployment diagram show? Where artifacts run on nodes and how nodes communicate.

Artifact versus component? A component is logical; an artifact is the physical file (jar, image, script) that manifests it.

What makes a good dependency structure? No cycles, arrows pointing toward stable parts, and the domain independent of infrastructure through interfaces.

Constraints, profiles and practice

What is OCL? A formal, side-effect-free language to write invariants, preconditions, postconditions and derived values on UML models.

What is a stereotype? A label that extends a UML metaclass to give an element domain meaning, optionally with tagged values; a profile is a package of stereotypes.

What are forward, reverse and round-trip engineering? Forward: model to code. Reverse: code to model. Round-trip: keep both in sync. In practice, generate structure diagrams from code and draw intent diagrams by hand.

How do you make sure diagrams stay current? Store them as text in version control, generate structural diagrams in the build, review them in pull requests and keep only the ones that answer real questions.

Short exercises you may be given

  1. Draw the class diagram for a library with books, members and loans. Show multiplicity, an association class for the loan and state your assumptions.
  2. Draw the state machine of a traffic light with a pedestrian button. Include timers and ignored events.
  3. Find the flaw: a diagram where Order and Customer depend on each other and both hold lists of the other. Answer: a bidirectional cycle; make one direction navigable only, or introduce an interface.

Try a couple of them in the checker below, which verifies your multiplicities and finds cycles in a pair of classes.

Python Spot the flaw: cycles and bidirectional links

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Answer structure that works

  1. Give a one-sentence definition.
  2. Give a tiny example (two or three boxes).
  3. Mention a trade-off or a typical mistake.
  4. Connect it to code or a real project.

For example, on composition: "It is a strong whole-part relationship where the parts cannot outlive the whole. An Order owns its OrderLines. If you delete the order, the lines go too, which I implement with ON DELETE CASCADE or by having the order create and own the lines."

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a transition label contain?

    Event, optional guard in brackets and optional action after the slash.
  2. 2. How does a component differ from a package?

    Packages have no run-time meaning; components do.
  3. 3. Which statement about composition is true?

    Composition expresses ownership and shared lifetime.
  4. 4. What is a good answer structure in an interview?

    Short, concrete and practical answers show that you can use UML.

Summary

  • Know the two families of diagrams and what question each answers.
  • Be able to explain relationships, state machine notation, components versus packages and artifacts.
  • Mention OCL, stereotypes and the engineering directions at a conceptual level.
  • Practice sketching small models and finding flaws.
  • Structure each answer: definition, example, trade-off, link to code.

Next: Back to the UML track