ozayezerceli's picture
Upload 10 files
7e8b8ca verified
raw
history blame
2.99 kB
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()