UML Models Unpacked: Design Patterns and Practical Cases

UPI Study › Courses › System Analysis and Design › Free lessons › Lesson 4.3 Free with a free account

UML Models Unpacked: Design Patterns and Practical Cases

System Analysis and Design · Chapter 4: Requirements Validation, Modeling, and UMLSection 4.3 · lesson 26 of 6910 min · free with a free account

← Defining System Boundaries with Context DiagramsNext lesson: Getting Started with Use Case Diagrams, Documents, and Templates →

Earn 3 college credits for System Analysis and DesignRecommended for credit by NCCRS · Computer Science 390 · self-paced · one payment, lifetime access

In this lesson

Sequence, activity, and state machine diagrams - and 4 patterns - in one checkout.

  • Trace UML's origins and its structural vs. behavioral taxonomy
  • Read sequence, activity, and state machine diagrams
  • Distinguish creational, structural, and behavioral patterns: Singleton, Factory, Observer, MVC
  • Apply diagrams and patterns together in one practical case

Transcript

Everything said in the video, section by section (1,353 words). Read along, or search it.

Requirements Validation, Modeling, and UML

UML Models and Design Patterns

Up to now, our models have described what a system must do, and where its boundary lies. This section moves closer to design. We will meet three behavioral U M L diagrams, sequence, activity, and state machine diagrams. Then four design patterns, Singleton, Factory, Observer, and Model View Controller. And we will finish by applying all of them to a single online bookstore checkout.

Origins and Taxonomy

The Unified Modeling Language

The unified modeling language, or U M L, emerged in the mid nineteen nineties. It came from merging several competing object-oriented modeling notations. Primarily the work of Grady Booch, James Rumbaugh, and Ivar Jacobson, at Rational Software. The Object Management Group began standardizing it in nineteen ninety-seven. It has served as the common notation for object-oriented systems ever since. U M L diagrams fall into two broad families. Structural diagrams show the static parts of a system, what exists and how it is organized. Class, object, component, and deployment diagrams are structural. Behavioral diagrams show how the system behaves over time, or in response to events. Use case, sequence, activity, and state machine diagrams are behavioral. Every example that follows models the same online bookstore checkout, so you can compare them directly.

Figure 4.1

Sequence Diagram: Who Talks to Whom, in What Order

Start with the sequence diagram. It shows the participants in one specific scenario as vertical lifelines. And it shows the ordered messages between them, read from top to bottom. It answers one question. In what order do these parts talk to each other, to carry out this scenario? Solid arrows are calls. Dashed arrows are returns. In the checkout, message one runs from the customer to CheckoutUI. Select payment method. Message two, CheckoutUI asks PaymentService to process the payment. Message three returns, payment confirmed. Message four, CheckoutUI asks InventoryService to reduce stock. Message five returns, stock updated. And message six, CheckoutUI shows the confirmation to the customer. Notice that CheckoutUI sits at the center. It receives the choice, delegates the work, and only then reports back. A sequence diagram makes that coordination explicit, in a way a written description does not.

Figure 4.2

Activity Diagram: The Logic Behind One Call

Next, the activity diagram. It shows the flow of control through a process. A start point, a series of actions, decision points where the flow branches, and one or more end points. It resembles a flowchart, with more formal notation available for concurrency when a process needs it. Here is order processing. The process checks inventory, then reaches a decision. Is the item in stock? If yes, it processes the payment, updates inventory, and sends a confirmation. If no, it notifies the customer of a backorder. Compare this with the sequence diagram. The sequence diagram showed which participants talk to each other. The activity diagram shows the logic behind one of those calls. What process the order actually involves.

Figure 4.3

State Machine Diagram: The Life of One Order

The third diagram is the state machine diagram. It shows the distinct states a single object can be in, over its lifetime, and the events that move it from one state to the next. Here, the object is an order. It starts in the placed state. The event payment received moves it to paid. Shipped moves it to shipped. Delivered moves it to delivered, and its life ends. There is also a separate path. The cancel event moves an order to cancelled. But notice where that path starts. Only from placed. Once an order is paid, the diagram offers no route to cancelled. An activity diagram models a process. A state machine models the life of one object, across many processes.

Design Patterns

Reusable Solutions, 3 Categories

Now to design patterns. A design pattern is a reusable, well-tested solution to a common design problem. It is expressed at the level of classes and objects, rather than as ready-to-use code. Patterns fall into three categories, based on the kind of problem they solve. Creational patterns address how objects are created, so a system is not tightly bound to specific classes. Here, that means Singleton and Factory. Structural patterns address how classes and objects are composed into larger, working structures. Here, Model View Controller. And behavioral patterns address how objects communicate and share responsibility. Here, Observer.

Creational Patterns

Singleton and Factory

Singleton ensures a class has only one instance, and provides a single point of access to it. It suits situations where many parts of a system need to share exactly one resource. A configuration object, or a logging service, for example, without each part creating its own copy. But used carelessly, Singleton can turn into hidden global state, which makes a system harder to test. So it is best reserved for resources that genuinely should exist only once. Factory defines a separate method or class responsible for creating an object. The calling code does not need to know which concrete class it actually receives. That is useful whenever a system must choose among several related classes at runtime. For example, a checkout system that creates the right payment-processor object, based on the method the customer selects.

Behavioral Pattern

Observer

Observer is a behavioral pattern. It defines a one-to-many dependency between objects. When one object, called the subject, changes state, every dependent object, called an observer, is notified automatically, and updates itself. The subject does not need to know anything about its observers, beyond the fact that they should be notified. In the bookstore, InventoryService updates a stock count. Several parts of the storefront need to reflect that change. A stock counter, and a low-stock banner. Observer lets both update, without InventoryService needing to know about either one. Observer is also the mechanism that typically connects a model to its view. Which brings us to the next pattern.

Structural Pattern - Figure 4.4

Model-View-Controller (MVC)

Model View Controller, or M V C, separates an application into three cooperating parts. The controller handles user input, and updates the model. The model holds the data and the business logic. And the view is what the user sees. When the model changes, it notifies the view, and the view updates. In the checkout, those parts are the CheckoutController, the OrderModel, and the CheckoutView. Keeping the three responsibilities separate has a clear payoff. A change to how data is displayed does not require touching the logic that manages that data, and the reverse. And look at that notify and update step, from model to view. That is Observer at work, inside M V C. It is why the two patterns are so often discussed together.

A Practical Case

One Checkout, Every Tool at Once

Now put it all together, in one practical case. The sequence diagram captures how CheckoutUI, PaymentService, and InventoryService collaborate during one checkout. Inside that scenario, CheckoutUI uses a factory, to create the right payment processor for the method the customer chose. The activity diagram expands step two, showing the branching logic behind processing the order, including the out-of-stock case. Once an order exists, the state machine tracks its lifecycle, from placed to delivered, or out to cancelled. A single Singleton logging service records events from every part of this flow. And the storefront itself is organized as M V C, with the view kept in sync through Observer. The lesson is that these are not competing choices. A single real system typically uses several diagrams, and several patterns, together.

Key Terms

The Vocabulary of This Section

Let's lock in the key terms. A sequence diagram shows the ordered messages between participants, in one scenario. An activity diagram shows the flow of control, with its branches, through a process. A state machine diagram shows the states one object moves through, and the events that move it. A design pattern is a reusable, well-tested solution to a common design problem. Singleton restricts a class to one shared instance. Factory creates objects without naming the concrete class. Observer notifies dependents automatically. And M V C separates data, display, and input handling.

Key Takeaways

What to Carry Forward

To pull this together. U M L splits into structural diagrams and behavioral diagrams. Sequence, activity, and state machine diagrams are all behavioral. A sequence diagram orders the messages in one scenario. An activity diagram shows the branching logic of a process. A state machine tracks one object's lifecycle. Design patterns are creational, structural, or behavioral, addressing creation, composition, and communication. Singleton, Factory, Observer, and M V C each solve a specific, recurring problem. And a real system, like the bookstore checkout, typically uses several of them together.

About System Analysis and Design at UPI Study

System Analysis and Design (Computer Science 390) is a self-paced online course of 69 video lessons in 9 chapters, from the analyst's role and requirements to UML modeling, interface and database design, testing, maintenance and project management. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Software Engineering vs Systems Analysis

Why take it here

Why students take System Analysis and Design with UPI Study

From business problem to working systemSystem Analysis and Design teaches how analysts study a business need and turn it into a system design: requirements, UML and data-flow models, interface and database design, implementation and project management. It is a core course in information systems and IT degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

System Analysis and Design carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About UML Models Unpacked: Design Patterns and Practical Cases

What is the difference between structural and behavioral UML diagrams?
Structural UML diagrams show the static parts of a system, what exists and how it is organized, while behavioral diagrams show how the system behaves over time or in response to events. Class, object, component, and deployment diagrams are structural. Use case, sequence, activity, and state machine diagrams are behavioral. UML itself emerged in the mid-1990s from the work of Grady Booch, James Rumbaugh, and Ivar Jacobson at Rational Software.
What is the difference between a sequence diagram, an activity diagram, and a state machine diagram?
A sequence diagram shows the ordered messages between participants in one scenario, an activity diagram shows the branching flow of control through a process, and a state machine diagram shows the states one object moves through and the events that move it. In an online checkout, the sequence diagram shows who calls whom, the activity diagram shows the in-stock decision, and the state machine tracks an order from placed to delivered.
What are the three categories of design patterns?
Design patterns fall into creational, structural, and behavioral categories. Creational patterns, such as Singleton and Factory, address how objects are created so a system is not tightly bound to specific classes. Structural patterns address how classes and objects are composed into larger structures. Behavioral patterns, such as Observer, address how objects communicate and share responsibility. Each pattern is a reusable, well-tested solution expressed at the level of classes and objects.
How does the Observer pattern relate to Model-View-Controller?
Observer is typically the mechanism that keeps the view in sync with the model in Model-View-Controller. In MVC, the controller handles user input and updates the model, the model holds data and business logic, and the view displays it. When the model changes, it notifies the view, which updates itself. That notify-and-update step is Observer's one-to-many dependency, where a subject automatically notifies its dependents.

About the System Analysis and Design course

How many college credits is System Analysis and Design?
System Analysis and Design (Computer Science 390) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does System Analysis and Design cost and what is included?
$250, paid once, with lifetime access: all 69 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does System Analysis and Design take?
It is self-paced with no deadlines. The 69 lessons total about 9 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in System Analysis and Design.

69 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

System Analysis and Design
3 credits · NCCRS
Enroll →