import streamlit as st from utils.code_examples import coupling_examples from utils.quiz import coupling_quiz st.title("Coupling in Software Architecture") st.write(""" Coupling refers to the degree of interdependence between software modules. Low coupling is typically a sign of a well-structured computer system and a good design. """) st.subheader("Types of Coupling") st.write(""" 1. **Tight Coupling**: Modules are highly dependent on each other. 2. **Loose Coupling**: Modules are relatively independent of each other. """) st.subheader("Examples of Coupling") for i, (title, description, code) in enumerate(coupling_examples, 1): st.markdown(f"### Example {i}: {title}") st.write(description) st.code(code, language="python") st.subheader("Interactive Exercise: Identify Coupling Issues") st.write("Analyze the following code snippets and identify the type of coupling present.") code1 = """ class Database: def get_user(self, user_id): # database logic here pass class UserService: def __init__(self): self.db = Database() def get_user_info(self, user_id): return self.db.get_user(user_id) """ code2 = """ class Database: def get_user(self, user_id): # database logic here pass class UserService: def __init__(self, database): self.db = database def get_user_info(self, user_id): return self.db.get_user(user_id) """ st.code(code1, language="python") user_answer1 = st.radio("What type of coupling is present in the first example?", ("Tight Coupling", "Loose Coupling")) st.code(code2, language="python") user_answer2 = st.radio("What type of coupling is present in the second example?", ("Tight Coupling", "Loose Coupling")) if st.button("Check Answers"): if user_answer1 == "Tight Coupling" and user_answer2 == "Loose Coupling": st.success("Correct! The first example shows tight coupling, while the second shows loose coupling.") else: st.error("Not quite. Try again!") st.markdown("---") st.subheader("Quiz: Coupling Concepts") coupling_quiz()