Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring - Part 3 #168

Open
ageorgou opened this issue Dec 4, 2020 · 0 comments
Open

Refactoring - Part 3 #168

ageorgou opened this issue Dec 4, 2020 · 0 comments
Labels

Comments

@ageorgou
Copy link
Collaborator

ageorgou commented Dec 4, 2020

This follows on from #167.

Stage 3: Object-oriented structure

We will now look at at how to represent and manipulate this data using our own user-defined objects.

Instead of a dictionary, we will define two classes, which will represent a single person and the whole group. We will restructure our code so that group functions apply directly to the group, instead of the person having all of the methods.
Again, you may also wish to refer to the course notes on object-oriented design.

Take a look at the file initial_two_classes.py to see one possible way in which the code could be structured.

Internally, the Group class still uses a dictionary to track connections, but someone using the class does not need to be aware of that. We have implemented some methods for these classes, but not everything that is required (the remaining methods have pass instead of actual code).

Your task:

  1. You should have the files from the previous parts of the exercise.
  2. Fill in the remaining method definitions.
  3. Update the section at the end of the file so that it creates the same group as in the previous example, but using the new classes you have defined.
  4. Run the file to make sure it gives the same results as before (that is, the assertions still pass).
  5. Commit your changes.
  6. Think of the benefits and drawbacks of the object-oriented structure compared to the original approach (collection of functions).
  7. If you have time, think of other changes you consider useful and try them.
@ageorgou ageorgou added the week09 label Dec 4, 2020
umitozmen added a commit to umitozmen/rse-classwork-2020 that referenced this issue Dec 7, 2020
DavidScobie added a commit to DavidScobie/rse-classwork-2020 that referenced this issue Dec 9, 2020
premal-varsani added a commit to premal-varsani/rse-classwork-2020 that referenced this issue Dec 9, 2020
@Tiantian-H Tiantian-H mentioned this issue Dec 10, 2020
nuttamas added a commit to nuttamas/rse-classwork-2020 that referenced this issue Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant