JayLoomis / cornpython

0 stars 0 forks source link

Exercise 3: Refinement 2 - Making a simple database #4

Open JayLoomis opened 3 years ago

JayLoomis commented 3 years ago

In this refinement, you'll expand on what you've done to make a simple in-memory database to track customer contacts using the dictionary structure that you made for the baseline exercise and the contact time tracking in refinement 1 as records for your database of customers.

Let's go over the use case for the application you're building.

Our user is a business person who has to manage multiple customers. She wants to keep track of how frequently she contacts each customer, so she can stay in their consciousness over time.

One use case would be managing leads for a realtor: people give you names of friends and family who are thinking about buying a house. You'll want to periodically send them inquiries to make sure that when they decide it's time to buy they think of you.

Another use case would be a freelance artist tracking art directors at various companies. You'd want to send regular inquiries to make sure you're on their radar.

Requirements

This exercise has two primary purposes: first, you're building the infrastructure to store an in-memory database of contact information, building on the work that you did in previous parts of the exercise; second, you're starting to think about the user interface to deal with managing the database.

Update your program to:

JayLoomis commented 3 years ago

Before you complete this one, please go back and align your solution to the requirements. Your current park employee framework isn't what the assignment calls for.

JayLoomis commented 3 years ago

Before you're done with this refinement, refactor your code to make this all object oriented.

You should create at least two classes, each in its own module for this. The first is a class for individual records in the database. The second is for the program's user interface. Note that the UI class will only be used for a single object, which might seem weird, but is not uncommon.

JayLoomis commented 3 years ago

Here's a class design that makes sense to me.

datapawn commented 3 years ago

AAAAh! Okay. That's super interesting. I've got something different. I'm sure you'll be able to explain it to me.

I've started to comment the ascii art file. Will quit at 9"15, hard stop. I need to take 45 min or so for me.

On Mon, Jan 18, 2021 at 8:58 PM Jay Loomis notifications@github.com wrote:

Here's a class design that makes sense to me.

  • Create a class that encapsulates a single contact record. This should contain all the data that you're currently storing for a record. For now, don't worry about creating setter/getter methods. Do include any other functions that manipulate this data.
  • Create a class that manages the database. The primary purpose of this class is to manage the list of contact record classes that is the database. Create methods to access the records in the ways that you need. Adding, removing, finding, and deleting are no brainers, but think about it and add anything less obvious.
  • Create a single-use class for the application's interface. Use the same class for user input (control) and program display (view), because this is such a small application.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/JayLoomis/cornpython/issues/4#issuecomment-762601846, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRRLDQJBIIMGKXCXTJGOYTS2UGP3ANCNFSM4VAV3FNA .

--

Andrew Henderson graypawn.carbonmade.com http://graypawn.carbonmade.com

datapawn commented 3 years ago

I could use some coaching on how to create the UX and Database classes from the existing code i've got. The setup i have now, the UX is a loop that runs until you tell it what you want to do: search, connect, new, exit.

If i build those into the UX class, does it then call f() from the Database class? Does the database class initialize into multiple records, or into a single "database?" maybe we should do a bonus meeting, super short, tomorrow afternoon?

JayLoomis commented 3 years ago

Your application class (which we’ve been calling a UX class) should contain all the stuff you need to make the application work. That means it’ll have an instance of the DB class that it uses to interface with the data.

We can chat about this a little later today if you have time.

On Tue, Jan 19, 2021 at 9:58 PM Graypawn notifications@github.com wrote:

I could use some coaching on how to create the UX and Database classes from the existing code i've got. The setup i have now, the UX is a loop that runs until you tell it what you want to do: search, connect, new, exit.

If i build those into the UX class, does it then call f() from the Database class? Does the database class initialize into multiple records, or into a single "database?" maybe we should do a bonus meeting, super short, tomorrow afternoon?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JayLoomis/cornpython/issues/4#issuecomment-763356026, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARB73XSB5IPT2NX5TDX6VDS2ZWIVANCNFSM4VAV3FNA .

-- Jay Loomis Programming Writer Creative Writer Interdisciplinary Artist www.jayloomis.com

datapawn commented 3 years ago

So I'm going to have to re-write the features i've got now, if they're going to be separate from the Database class - right now the code i've got updates and creates new sample records only, and does directly through the UI. To not have the Database using UI stuff, i'll have to rebuild how it works, i think?

datapawn commented 3 years ago

I've pushed my code for today (1-23-21) - i'm still trying to sort out two things: How much do i adhere to "if you're talking to the user, it's UI" when building out these class objects? How do i work with libraries a class needs? I can't seem to get my current iteration to recognize the datetime library anymore.

JayLoomis commented 3 years ago

How much do i adhere to "if you're talking to the user, it's UI" when building out these class objects?

100% Your internal data classes should have no knowledge of the user, and the user should have no knowledge of them. Separation of concerns! Black box encapsulation! Buzzwords!

How do i work with libraries a class needs? I can't seem to get my current iteration to recognize the datetime library anymore.

No difference between this and any other module. The file you checked in only has an import statement for uuid, but it's inside a class for some reason. You need to import datetime if you're going to use it. All of your imports should be at the top of the file, after your file docstring. Look to PEP-8 for style information about what order to put the imports in and whatnot.