File size: 2,991 Bytes
7e8b8ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import streamlit as st
from utils.code_examples import cohesion_examples
from utils.quiz import cohesion_quiz
st.title("Cohesion in Software Architecture")
st.write("""
Cohesion refers to the degree to which the elements within a module belong together.
High cohesion is generally associated with good software design.
""")
st.subheader("Types of Cohesion")
st.write("""
1. **Functional Cohesion**: All elements of the module are related to the performance of a single function.
2. **Sequential Cohesion**: Elements of a module are involved in activities where output from one element serves as input to another.
3. **Communicational Cohesion**: Elements of a module operate on the same data.
4. **Procedural Cohesion**: Elements of a module are involved in different and possibly unrelated actions that must be performed in a specific order.
5. **Temporal Cohesion**: Elements are related by the fact that they are processed at a particular time in program execution.
6. **Logical Cohesion**: Elements perform similar operations, but these operations are unrelated.
7. **Coincidental Cohesion**: Elements have no meaningful relationship to one another.
""")
st.subheader("Examples of Cohesion")
for i, (title, description, code) in enumerate(cohesion_examples, 1):
st.markdown(f"### Example {i}: {title}")
st.write(description)
st.code(code, language="python")
st.subheader("Interactive Exercise: Identify Cohesion Types")
st.write("Analyze the following code snippets and identify the type of cohesion present.")
code1 = """
class UserManager:
def create_user(self, username, email):
# logic to create user
pass
def delete_user(self, user_id):
# logic to delete user
pass
def update_user(self, user_id, new_data):
# logic to update user
pass
"""
code2 = """
class ReportGenerator:
def generate_sales_report(self):
# logic for sales report
pass
def generate_inventory_report(self):
# logic for inventory report
pass
def send_email(self, report):
# logic to send email
pass
"""
st.code(code1, language="python")
user_answer1 = st.selectbox("What type of cohesion is present in the first example?",
("Functional", "Sequential", "Communicational", "Procedural", "Temporal", "Logical", "Coincidental"))
st.code(code2, language="python")
user_answer2 = st.selectbox("What type of cohesion is present in the second example?",
("Functional", "Sequential", "Communicational", "Procedural", "Temporal", "Logical", "Coincidental"))
if st.button("Check Answers"):
if user_answer1 == "Functional" and user_answer2 == "Logical":
st.success("Correct! The UserManager class shows functional cohesion, while the ReportGenerator class shows logical cohesion.")
else:
st.error("Not quite. Try again!")
st.markdown("---")
st.subheader("Quiz: Cohesion Concepts")
cohesion_quiz()
|