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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of System Analysis and Design.
Lesson complete
Earn the 3 college credits for System Analysis and Design
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Getting Started with Use Case Diagrams, Documents, and Templates →← Defining System Boundaries with Context DiagramsNext lesson: Getting Started with Use Case Diagrams, Documents, and Templates →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Why take it here
Why students take System Analysis and Design with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
What is the difference between a sequence diagram, an activity diagram, and a state machine diagram?
What are the three categories of design patterns?
How does the Observer pattern relate to Model-View-Controller?
About the System Analysis and Design course
How many college credits is System Analysis and Design?
How much does System Analysis and Design cost and what is included?
Which universities accept UPI Study credits?
How long does System Analysis and Design take?
How are the exams done?
How do my credits reach my college?
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.
3 credits · NCCRSEnroll →