Lesson Materials: Use Case Diagrams in Java Development
I. Introduction Materials:
Slide 1: Title Slide
o Title: "Understanding Use Case Diagrams in Java Development"
o Your Name/Instructor Name
o Date
Slide 2: What is a Use Case Diagram?
o Definition: "A visual representation of the interaction between users
(actors) and a system, used to define system requirements."
o Key points:
Part of UML (Unified Modeling Language).
Focuses on "what" the system does, not "how."
Used in early stages of software development.
Slide 3: Why Use Case Diagrams?
o Question: "Why is it important to understand user interactions before
coding?"
o Bullet points:
Avoid misunderstandings.
Ensure the software meets user needs.
Provides a clear overview of system functionality.
II. Components of a Use Case Diagram Materials:
Slide 4: Actors
o Definition: "External entities that interact with the system (users, other
systems, devices)."
o Visual: Simple stick figure icons representing various actors.
o Examples:
Customer
Administrator
Bank Teller
Slide 5: Use Cases
o Definition: "Specific goals or tasks that an actor wants to accomplish
with the system."
o Visual: Oval shapes representing use cases.
o Examples:
"Login"
"Place Order"
"Generate Report"
Slide 6: Relationships
o Visual: Diagram showing:
Association (line between actor and use case)
Include (dashed arrow labeled "<<include>>")
Extend (dashed arrow labeled "<<extend>>")
Generalization (solid arrow with an open head)
o Descriptions of each relationship type.
Slide 7: System Boundary
o Visual: A rectangle surrounding the use cases.
o Definition: "Defines the scope of the system."
III. Purpose and Importance Materials:
Slide 8: Purpose of Use Case Diagrams
o Bullet points:
Requirement gathering.
Scope definition.
Stakeholder communication.
Test case generation.
Slide 9: Importance in Java Development
o Bullet points:
Architectural design.
User story definition.
Class/method identification.
Ensuring user needs are met.
Slide 10: Connecting Use Cases to Java
o Example:
Use Case: "Withdraw Money"
Java Method: public void withdrawMoney(double amount)
o Explanation of how Use cases directly relate to code.
IV. Creating Use Case Diagrams Materials:
Slide 11: Example Scenario: Online Library System
o Scenario description: "A system where users can browse books, borrow
books, and return books."
o Actors: Librarian, Member
o Use Cases: Browse Books, Borrow Book, Return Book, Manage Member
Accounts.
Slide 12: Drawing the Diagram
o Step-by-step visuals showing how to add actors, use cases, and
relationships.
o Show system boundaries.
Handout 1: Use Case Diagram Exercise
o Scenario: "A simple online shopping system."
o Instructions: "Identify the actors and use cases, and create a Use Case
Diagram."
o Blank space for drawing the diagram.
Handout 2: Use Case Diagram Relationship Definitions
o Clear and concise definitions of Association, Include, Extend, and
Generalization.
V. Review and Conclusion Materials:
Slide 13: Review
o Recap of key concepts: Actors, Use Cases, Relationships, System
Boundary.
o Questions for student review.
Slide 14: Q&A
o "Any questions?"
Slide 15: Conclusion
o Summary of the importance of Use Case Diagrams.
o Encouragement to practice creating diagrams.
o List of recommended UML diagramming tools.
Additional Materials:
Example Use Case Diagram: A detailed diagram of a real-world system
(e.g., ATM system, online banking).
UML Diagramming Tool Tutorial: A brief guide on how to use a specific
tool (draw.io, Lucidchart).
Glossary of Terms: Definitions of key terms (actor, use case, association,
etc.).
Java Code Snippets: Small Java code examples that correspond to specific
use cases.
Tips for Using the Materials:
Use visuals and examples to make the concepts clear.
Encourage student participation and questions.
Provide hands-on exercises to reinforce learning.
Connect the concepts to real-world Java development.
Provide links to online resources that can provide further information.
When using the slide materials, allow for plenty of time for questions, and
discussion.
By using these materials, you can create an engaging and informative lesson on
Use Case Diagrams in Java development.
// Sample Java code demonstrating how Use Case concepts can translate into code
// Scenario: Online Shopping System
// Use Cases:
// - Browse Products
// - Add to Cart
// - Checkout
// Actors:
// - Customer
public class OnlineShoppingSystem {
private ShoppingCart cart;
public OnlineShoppingSystem() {
this.cart = new ShoppingCart();
}
// Corresponds to "Browse Products" Use Case
public void browseProducts() {
// Simulate browsing products (e.g., fetching from a database)
System.out.println("Displaying available products...");
// ... code to fetch and display products ...
}
// Corresponds to "Add to Cart" Use Case
public void addToCart(Product product, int quantity) {
cart.addItem(product, quantity);
System.out.println(quantity + " " + product.getName() + "(s) added to cart.");
}
// Corresponds to "Checkout" Use Case
public void checkout() {
double total = cart.calculateTotal();
System.out.println("Checkout initiated. Total: $" + total);
// ... code to process payment and complete order ...
}
public static void main(String[] args) {
OnlineShoppingSystem system = new OnlineShoppingSystem();
Product product1 = new Product("Laptop", 1200.00);
Product product2 = new Product("Mouse", 25.00);
system.browseProducts();
system.addToCart(product1, 1);
system.addToCart(product2, 2);
system.checkout();
}
}
class ShoppingCart {
private java.util.HashMap<Product, Integer> items;
public ShoppingCart() {
this.items = new java.util.HashMap<>();
}
public void addItem(Product product, int quantity) {
items.put(product, quantity);
}
public double calculateTotal() {
double total = 0.
for (java.util.Map.Entry<Product, Integer> entry : items.entrySet()) {
Product product = entry.getKey();
int quantity = entry.getValue();
total += product.getPrice() * quantity;
}
return total;
}
}
class Product {
private String name;
private double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
}
Explanation and Connection to Use Case Diagram:
1. Use Cases to Methods:
o The "Browse Products," "Add to Cart," and "Checkout" use cases are
directly translated into methods within the OnlineShoppingSystem
class.
o This demonstrates how use cases define the functional requirements of
the system, which are then implemented as methods in Java.
2. Actors to Interactions:
o The "Customer" actor interacts with the system by calling these
methods.
o The main method simulates this interaction, showing how a customer
would use the system.
3. Data and Logic:
o The ShoppingCart and Product classes represent the data and logic
involved in the use cases.
o The ShoppingCart class handles the "Add to Cart" and "Checkout"
functionality, while the Product class stores product information.
4. Simplified Example:
o This is a simplified example, but it illustrates the basic principle of how
use cases can guide Java code development.
o In a real world application, the code within each method would be
much more complex.
5. Clarity and Organization:
o Using Use Cases helps organize the code. Each Use case is represented
by a function, which makes the code easier to understand and
maintain.
Key Takeaways:
Use Case Diagrams help define the system's functionality.
These functionalities are then implemented as methods in Java classes.
The interaction between actors and the system is simulated through method
calls.
This process allows for a clear translation from requirements to code.
The use of classes allows for the data used by the use cases to be organized.