This document provides the structure to evidence your relevant knowledge and skills for this activity.
- Each answer should be complete, well-articulated, and within the specified word count limits (if added) for each question.
- Please make sure all external sources are properly cited.
- You must use your own words. If you use generative AI in any capacity, you must include your full chat transcripts.
-
Please follow the instructions in this document to make the necessary changes to the code.
-
When requested to upload evidence, upload all screenshots to
screenshots/
and embed them in this document. For example:
![Example Running Code](screenshots/screenshot1.png)
- You must upload the code into this GitHub repository.
- While you can use a branch, your code should be in main when you submit.
- Upload a zip of this repository to Blackboard when you are ready to submit.
- Feedback will be provided via GitHub, but you will be notified of your result via Blackboard
The use of Raspberry Pi and SenseHat is optional for this activity. You can use the included sense_hat.py
file to simulate the SenseHat on your computer.
If you use a PI, please delete the sense_hat.py
file.
This project relies on visual patterns that appear on an LED matrix. If you have any accessibility requirements, you can use the udl/accessible
branch to complete the project. This branch provides an accessible code version that uses text-based patterns instead of visual ones.
Please discuss this with your lecturer before using that branch.
Address the following tasks and questions based on the code provided in this repository.
- Clone this repository
- Run the project locally by executing the
main.py
file - Evidence this by providing screenshots of the project directory structure and the output of the
main.py
file
If you are running on a Raspberry Pi, you can use the following command to run the project and then screenshot the result:
ls
python3 main.py
Note: Ignore the
sense_hat.py
file when answering the questions below
- List all the classes you identified in the project. Indicate which classes are base classes and which are subclasses. For subclasses, identify all direct base classes. Use the following table for your answers:
Class Name | Super or Sub? | Direct parent(s) |
---|---|---|
NotReal | Sub | NotRealParent |
...
- Explain the concept of 'abstraction' as demonstrated in this project. (Max 150 words)
Your answer here
- What is the name of the process of deriving from base classes? What is its purpose in this project? (Max 150 words)
Your answer here
Compare and contrast the classes Happy and Sad.
- What is a key difference between the two classes?
Your answer here
- What are the key similarities?
Your answer here
- What difference stands out the most to you and why?
Your answer here
- How do these differences affect the functionality of these classes
Your answer here
- Which class(s) utilize the functionality of the SenseHat?
Your answer here
- Which of these classes directly interact with the SenseHat functionalities?
Your answer here
- Discuss the hiding of the SenseHAT in terms of encapsulation (100-200 Words)
Your answer here
Unlike the Happy
smiley, the current implementation of the Sad
smiley does not possess the ability to blink. Let's first explore how blinking has been implemented in the Happy smiley by examining the blink() method, which takes one argument that determines the duration of the blink.
- Understanding Blink Mechanism: In your own words, explain how the
blink()
method enables the Happy smiley to blink. What role does the argument play in this method?
Your answer here
-
Implement Blink in Sad Class:
- Create a new method called
blink
within the Sad class. Ensure you use the same method signature as in the Happy class:
def blink(self, delay=0.25): pass # Replace 'pass' with your implementation
- Create a new method called
-
Code Implementation: Implement the code that allows the Sad smiley to blink. Use the implementation from the Happy smiley as a reference. Ensure your new method functions similarly by controlling the blink duration through the
delay
argument. -
Testing the Implementation:
- Test the new blink functionality on your Raspberry Pi or within the Python classes provided. You might need to adjust the
main.py
script to incorporate the Sad Smiley's new blinking capability.
Include a screenshot of the sad smiley or the modified main.py
:
-
Observe and document the Sad smiley as it blinks its eyes. Describe any adjustments or issues encountered during implementation.
Your answer here
Previously, you implemented the blink functionality for the Sad smiley without utilizing the class
Blinkable
. Assuming you did not useBlinkable
(even if you actually did), consider how the Sad smiley could blink in a similar manner to the Happy smiley without this specific class.-
Class Type Analysis: What kind of class is
Blinkable
? Inspect its superclass for clues about its classification.Your answer here
-
Class Implementation:
Blinkable
is a class intended to be implemented by other classes. What generic term describes this kind of class, which is designed for implementation by others? Clue: Notice the lack of any concrete implementation and the naming convention.
Your answer here
- OO Principle Identification: Referring to your answer in question (2), which Object-Oriented (OO) principle does this represent? Choose from the following and justify your answer in 1-2 sentences: Abstraction, Polymorphism, Inheritance, Encapsulation.
Your answer here
- Implementation Flexibility: Explain why you were able to grant the Sad Smiley a blinking feature similar to the Happy Smiley's implementation, even without directly using
Blinkable
.
Your answer here
- Concept and Language Specificity: In relation to your response to question (4), what is this capability known as, and why is it feasible in Python and many other dynamically typed languages but not in most statically typed programming languages like C#? Clue This concept is hinted at in the title of this section.
Your answer here
While our current implementation predominantly features yellow smileys, emotional expressions like sickness or anger typically utilize colors like green, red, or orange. We'll explore the feasibility of integrating these colors into our smileys.
-
Defined Colors and Their Location:
- Which colors are defined and in which class(s)?
Your answer here
- What type of variables hold these colors? Are the values expected to change during the program's execution? Explain your answer.
Your answer here
- Add the color blue to the appropriate class using the appropriate format and values.
- Which colors are defined and in which class(s)?
-
Usage of Color Variables:
- In which classes are the color variables used?
Your answer here
- In which classes are the color variables used?
-
Simple Method to Change Colors:
-
What is the easiest way you can think to change the smileys to green? Easiest, not necessarily the best!
Your answer here
Here's a revised version of the "Flexible Colors – Step 1" section for the smiley project, incorporating your specifications for formatting and content updates:
Changing the color of the smileys once is straightforward, but it isn't very flexible. To facilitate various colors for smileys, it is advisable not to hardcode values in any class. This approach was identified earlier as a necessary change. Let's start by removing the built-in assumptions about color in our classes.
-
Add a method called
complexion
to theSmiley
class: Implement this instance method to returnself.YELLOW
. Using the term "complexion" instead of "color" provides a more abstract terminology that focuses on the meaning rather than implementation. -
Refactor subclasses to use the
complexion
method: Modify any subclass that directly accesses the color variable to instead utilize the newcomplexion
method. This ensures that color handling is centralized and can be easily modified in the future. -
Determine the applicable Object-Oriented principle: Consider whether Abstraction, Polymorphism, Inheritance, or Encapsulation best applies to the modifications made in this step.
-
Verify the implementation: Ensure that the modifications function as expected. The smileys should still display in yellow, confirming that the new method correctly replaces the direct color references.
This step is crucial for setting up a more flexible system for color management in the smiley display logic, allowing for easy adjustments and extensions in the future.
Having removed the hardcoded color values, we now enhance the base class to support dynamic color assignments more effectively.
-
Modify the
__init__()
method in theSmiley
class: Introduce a default argument namedcomplexion
and assignYELLOW
as its default value. This allows the instantiation of smileys with customizable colors. -
Introduce a new instance variable: Create a variable called
my_complexion
and assign thecomplexion
parameter to it. This step ensures that each smiley instance can maintain its own color state. -
Rationale for
my_complexion
: Using a distinct instance variable likemy_complexion
avoids potential conflicts with the method parameter names and clarifies that it is an attribute specific to the object. -
Bulk rename: We want to update our grid to use the value of complexion, but we have so many
Y
's in the grid. Use your IDE's refactor tool to rename all instances of the symbolY
toX
. WhereX
is the value of thecomplexion
variable. Include a screenshot evidencing you have found the correct refactor tool and the changes made.
-
Update the
complexion
method: Adjust this method to returnself.my_complexion
, ensuring that whatever color is assigned during instantiation is what the smiley displays. -
Verification: Run the updated code to confirm that Smileys still defaults to yellow unless specified otherwise.
With the foundational changes in place, it's now possible to implement varied smiley colors for different emotional expressions.
-
Adjust the
Sad
class initialization: In theSad
class's initializer method, change the superclass call to include thecomplexion
argument with the valueself.BLUE
, as shown:super().__init__(complexion=self.BLUE)
-
Test color functionality for the Sad smiley: Execute the program to verify that the Sad smiley now appears blue.
-
Ensure the Happy smiley remains yellow: Confirm that changes to the Sad smiley do not affect the default color of the Happy smiley, which should still display in yellow.
-
Design and Implement An Angry Smiley: Create an Angry smiley class that inherits from the
Smiley
class. Set the color of the Angry smiley to red by passingself.RED
as thecomplexion
argument in the superclass call.
-