Pattern advice from an LLM

This is a list of all prompts used in course 3 module 3, since the downloadable file named patterns_advice_prompts.txt just lists a few of them:

Promping for Company Data Project

You are an expert Python developer who builds readable code. Together we will work on an application that has a database to store information, code to retrieve data from the database, and analytics that will run on the retrieved data.

First, let’s create the database, which has a table for companies. The table will have three columns, the first is an id, the second the ticker for the company, the third is the name of the company. Create this, and synthesize data for 10 companies, adding that to the database.

Now add another table called ‘TimeSeries’ that has four columns, an id for the row, the id for one of the companies, a value, and a date. Populate this with about 100 values per company, and have the dates be successive.

Now create code that when given a company ticker or an ID that it will extract the data for that company, and the time series data and load it into an company object. This object should have fields for high_bollinger which is the same data type as the time series, low_bollinger which is the same, moving_average which is the same, and a grade field which is a string.

You are an expert in software design patterns, particularly those from the Gang of Four, designed to make coding and maintenance more efficient. Please analyze the following code and suggest some changes that I could make based on good software engineering practice with these design patterns.

Instead of making all the changes at once, please do them one at a time, going in order from Singleton to Factory to template Method to Strategy, and explain in detail why you made the changes and what impact they may have.

Enhance the following code to use the gang of gour patterns. Stricly follow the common convention for any pattern you choose.

Start by explaining the conventions for the Singleton pattern and then describe how the code modifications you made stricly follow the conventions.

Let’s go back to the factory pattern can you explain it in much more detail? It looks like this code may not benefit from it, but can you spectulate about extensions to the code taht might?

Go back to the code that adds data to the database and synthesize some foreign companies (which will have a unique ID, but the ticker is always “ZZZ”) and the data for them, both in the companies table and in the time series table.

Then fully explain the Factory pattern by having multiple company types: a Domestic Company that is denoted by its ticker, and a Foreign Company that is denoted by its ID. Create code that shows how.

Great the third patter you mentioned was the Template Method Pattern. Can you demostrate where, how, and why you would use it in this code? What advantages would it bring?

The example of how to use the postprocess_data method is very simple right now. What are some interesting examples of ways i could actually make use of the flexibility provided by that postprocess_data method?

Ok, so next let’s explore the strategy pattern. What is it, how does it work, why would you use it, and demonstrate and clearly explain the code for it.

Also please give me some scenarios where addtions to this code might be made easier with this pattern.

Thanks for this topic! You really made a comprehensive list of useful prompts. I hope this helps a lot of learners :slight_smile:

Cheers,
Lucas