Assignment2
docx
keyboard_arrow_up
School
Johns Hopkins University *
*We aren’t endorsed by this school
Course
645
Subject
Information Systems
Date
Dec 6, 2023
Type
docx
Pages
9
Uploaded by ColonelMusic12881
Software Systems Engineering
Assignment 2
Question01:
Explain why Design is an important activity in software systems engineering. Explain the
difference between design “in the small” and “in the large”.
Answer:
Design is a very important part of software systems engineering. There are some important factors why
design is important in software systems engineering.
Enhancing Scalability and Flexibility A well-thought-out design enables systems to scale seamlessly, accommodating growth and
evolving requirements. It provides the flexibility to incorporate new features and functionalities.
Optimizing Resource Utilization
Design influences how resources should allocated and utilized within a system. A thoughtful
design ensures efficient use of computing power, memory, and storage.
Enabling Effective Collaboration
Design acts as a blueprint that facilitates collaboration among developers. It provides a common
understanding and framework for team members to work cohesively.
Ensuring Security and Reliability
Design plays a critical role in fortifying software against security vulnerabilities. It involves
implementing robust authentication, authorization, and encryption mechanisms.
User-Centric Design Principles
Designing with the end-user in mind leads to intuitive and user-friendly software. It involves
gathering user feedback and incorporating it into the design process.
Design "in the Small"
Design "in the small" involves fine-tuning specific components and functionalities.
Design "in the Large"
Design "in the large" focuses on the overall structure and interactions of the system. It outlines the high-
level architecture and overall flow.
Question02:
Review and execute the Assignment2.py file and its 4 parts. Contrast the design of each of the 4 parts [10
points]
. Are some of the designs better than the others? If so, why? If not, why not? [10 points]
Answer:
All parts in the Python code are an approach to adding a pair of numbers using different techniques.
Part 1:
print
(
'
\n
Part 1'
)
print
(
'4+3='
,
4
+
3
)
print
(
'1+2='
,
1
+
2
)
print
(
'154+233='
,
154
+
233
)
print
(
'555+-444='
,
555
+
(
-
444
))
In Part 1, the calculations are hard-coded, meaning that the pairs are explicitly written out and the results
are calculated and printed one by one. This approach is straightforward but not scalable. If we have a
large dataset or want to perform similar operations on different sets of pairs, we would have to manually
code each one.
Part 2:
print
(
'
\n
Part 2'
)
show_add_pair
(
numbers
[
0
])
show_add_pair
(
numbers
[
1
])
show_add_pair
(
numbers
[
2
])
show_add_pair
(
numbers
[
3
])
In Part Two, the code uses a function show_add_pair
to calculate and display the result for each pair of
numbers. The numbers are stored in a list of numbers, and each pair is accessed using indexing. This is
more flexible than Part 1, as you can easily add more pairs or modify the existing ones without changing
the core logic.
Part 3:
print
(
'
\n
Part 3'
)
for n in numbers
:
show_add_pair
(
n
)
Part 3 also utilizes the show_add_pair
function, but it employs a loop to iterate through the list of pairs
(numbers) and applies the function to each pair. This is even more scalable and flexible compared to Part
2 because you can handle any number of pairs without having to write explicit lines of code for each one.
Part 4:
print
(
'
\n
Part 4'
)
[
show_add_pair
(
x
) for x in numbers
]
Part 4 employs a list comprehension to achieve the same result as Part 3. This approach is more concise as
it combines the loop
and function
call in a single line. It is an efficient way to apply a function to a list of
items.
Contrast of designs:
Parts 2, 3, and 4 are better designed compared to Part 1 because they use functions and loops to
handle the pairs of numbers. This makes the code more modular, scalable, and easier to maintain.
Among Parts 2, 3, and 4, Part 4 is the most concise because it uses a list comprehension. It
accomplishes the same task as Part 3 but in a more compact and elegant way.
Part 3 is still well-designed as it makes good use of a loop, providing a clear and readable way to
iterate through the list of pairs.
Part 2 is less preferable than Part 3 because it requires explicit indexing, which can be error-prone
if the list changes.
Question 03:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Review and execute the Assignment2.py file and its 4 parts. Write down requirements that could have led
to each of the 4 parts (you can use any specification type you like: natural language, structured, etc.)
Requirements that require a specific design, solution, or implementation are overly constrained and
should be avoided.
[10 points
]. Explain why the requirements are similar or different between the 4 parts
[10 points]
Answer:
Part1 Requirements:
1.
Display specific pairs:
The requirement might have been to display specific pairs of numbers with their sum, and these pairs were known beforehand.
2.
Avoiding function usage:
The requirement might have been to avoid defining a function for simplicity or because the task was very specific and did not require reusable code.
Part2 Requirements:
1.
Display pairs from a predefined list:
There could be a requirement to display the sum of pairs
stored in a predefined list numbers.
2.
Modularity:
The requirement might have been to separate the logic for displaying the sum of
pairs into a function show_add_pair
, which allows for better code organization.
Part3 Requirements:
1.
Display sums for multiple pairs:
The requirement might have been to display the sums for
multiple pairs of numbers stored in the numbers list.
2.
Efficiency and scalability
: The requirement could have been to ensure that the code can handle
any number of pairs without the need for explicit lines of code.
Part4 Requirements:
1.
Display sums for a list of pairs in a concise manner:
The requirement might have been to
achieve the same outcome as Part 3 but in a more concise way.
2.
Code efficiency:
The requirement could have been to write code that is efficient and compact,
utilizing Python features like list comprehensions.
Similarities and Differences in Requirements:
All parts aim to display the sum of pairs of numbers stored in the numbers list.
They all use the show_add_pair
function for displaying the sum, emphasizing code modularity
and reuse.
The requirements are similar in that they all involve the same core task. The differences lie in
how they approach achieving this task, with varying degrees of modularity, efficiency, and
scalability.
Parts 2, 3, and 4 are more scalable and flexible compared to Part 1. They allow for easy addition
or modification of pairs without changing the core logic. They also demonstrate a better coding
practice by utilizing functions and loops.
Question 04:
Explain how (or if) the Iterator pattern applies to Assignment2.py [15 points].
Answer:
The Iterator pattern is a behavioral design pattern that provides a consistent way to traverse a collection of
objects without exposing the underlying implementation. In Python, this pattern is integrated into the
language's core through features like iterators, which allow for iteration over sequences (e.g., lists, tuples,
strings) using loops and comprehensions.
Part 3 & Part 4
In part 3, numbers are a list of lists, where each inner list represents a pair of numbers.
The for loop iterates over each element in numbers
, treating them as individual pairs.
This makes it possible to apply the show_add_pair
function to each pair without having
to explicitly index them.
This part employs list comprehension, which is an advanced feature in Python that
combines a loop and the creation of a list in a concise manner. It iterates over each
element x in numbers
and applies the show_add_pair
function to it. The resulting
values are collected into a list.
In both Parts 3 and 4, the Iterator pattern is applied by abstracting away the details of how the
iteration occurs. The user of the code does not need to know the internal structure of numbers or
how the pairs are stored. Instead, they simply use the iterator construct (for loop or list
comprehension) to access and process each pair.
However, in Part 2
, the code directly accesses elements in numbers using indexing, which
doesn't fully leverage the Iterator pattern. While it is not incorrect, it is less idiomatic in Python
and can be less flexible if the structure of numbers changes.
Part 1
, on the other hand, does not utilize the Iterator pattern at all. It explicitly lists out and
processes each pair without any form of abstraction or iteration. This approach is static and not
suitable for cases where the collection size may vary or change over time.
Question 05:
How could you validate the requirements you wrote in Question 3? [15 points]
Answer:
To validate the requirements outlined for each part, we can analyze how well each part fulfills its
respective set of requirements
Part 1 Requirements:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Display specific pairs:
This requirement is met. Part 1 explicitly lists specific pairs of numbers
along with their sum.
Avoiding function usage:
This requirement is also met. Part 1 does not define a function but
directly prints out the pairs and their sums.
Part 2 Requirements:
Display pairs from a predefined list:
This requirement is met. Part 2 accesses pairs from the
predefined list numbers and displays their sums.
Modularity:
This requirement is partially met. While Part 2 separates the logic for displaying the
sum of pairs into a function (show_add_pair), it still directly accesses specific elements in the list.
A more modular approach would involve iterating through the list, which is achieved in Parts 3
and 4.
Part 3 Requirements:
Display sums for multiple pairs:
This requirement is fully met. Part 3 uses a loop to iterate
through the list of pairs and displays the sums for each pair.
Efficiency and scalability:
This requirement is met. Part 3 is efficient and scalable, as it can
handle any number of pairs without the need for explicit lines of code for each pair.
Part 4 Requirements:
Display sums for a list of pairs in a concise manner:
This requirement is fully met. Part 4
achieves the same outcome as Part 3 but in a more concise way, using a list comprehension.
Code efficiency:
This requirement is fully met. Part 4 utilizes list comprehension, which is an
efficient and compact way to apply a function to a list of items.
Validation Summary:
All the requirements listed for each part are effectively validated. The requirements are specific to the
design and implementation of each part, and they are appropriately assessed based on how well each part
fulfills them. The requirements for modularity, efficiency, and scalability are especially relevant in
evaluating the design choices made in Parts 2, 3, and 4.
Question 06:
Modify Assignment2.py, such that the line “0+1= 1” is added on each of the parts (i.e., 4 times). Explain,
in each case, the relative difficulty of adding this output to the code. Also, turn in your updated
Assignment2.py file. [10 points]
Answer:
To add the line "0+1= 1" to each part of the code, we need to consider the relative difficulty of making
this modification in each section:
Editing in numbers list:
numbers = [[
4
, 3
], [
1
,
2
], [
154
,
233
], [
555
,
-
444
],[
0
,
1
]]
def show_add_pair
(
pair
):
print
(
str
(
pair
[
0
]) + '+' + str
(
pair
[
1
]) + '= ' + str
(
pair
[
0
] + pair
[
1
]))
Updated Part1:
print
(
'
\n
Part 1'
)
print
(
'4+3='
,
4
+
3
)
print
(
'1+2='
,
1
+
2
)
print
(
'154+233='
,
154
+
233
)
print
(
'555+-444='
,
555
+
(
-
444
))
print
(
'0+1='
,
0
+
1
)
Updated Part2:
print
(
'
\n
Part 2'
)
show_add_pair
(
numbers
[
0
])
show_add_pair
(
numbers
[
1
])
show_add_pair
(
numbers
[
2
])
show_add_pair
(
numbers
[
3
])
show_add_pair
(
numbers
[
4
])
Updated Part3:
print
(
'
\n
Part 3'
)
for n in numbers
:
show_add_pair
(
n
)
Updated Part4:
print
(
'
\n
Part 4'
)
[
show_add_pair
(
x
) for x in numbers
]
Python Updated Code Output (Python File attached with this document)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help