Knowee
Questions
Features
Study Tools

Why do we use a dedicated method save() to insert a row into a table instead of saving the record in __init__?Group of answer choicesWe might need to create objects without saving them to the databaseThere's no real reason. It's just a conventionWe can't set the attributes and save the record in the same methodWe don't want to couple the creation of objects with saving records to a databaseI don't know. PreviousNext

Question

Why do we use a dedicated method save() to insert a row into a table instead of saving the record in init?Group of answer choicesWe might need to create objects without saving them to the databaseThere's no real reason. It's just a conventionWe can't set the attributes and save the record in the same methodWe don't want to couple the creation of objects with saving records to a databaseI don't know. PreviousNext

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

We use a dedicated method save() to insert a row into a table instead of saving the record in init for a couple of reasons:

  1. We might need to create objects without saving them to the database: There could be instances where we just want to create an object and not necessarily save it to the database immediately. Having a separate save() method allows us to do this.

  2. We don't want to couple the creation of objects with saving records to a database: This is about separation of concerns. The init method is for initialization of the object. The save() method is for persisting it to the database. By keeping these operations separate, our code is more flexible and easier to maintain.

This problem has been solved

Similar Questions

Using an ORM enables us to save entire Python objects in our database.Group of answer choicesTrueI don't know.False PreviousNext

Which method in Hibernate is used to save an entity to the database?save()commit()persist()insert()

A record is stored in one ________ in a table.Group of answer choicesAccessDataRowColumn

Append Query is used to ____________________________________________.Group of answer choicesCopy records from one or more tables and use them to create a new tableIt is used to attach records to a table from an outside sourceCopy records from one or more tables and add them to existing tableCopy records from one or more tables and use them to create a report

Which one of the following statements is used to create a table?Group of answer choicesCREATE table_name (column_name column_type);CREATE TABLE table_name (column_type column_name);CREATE TABLE table_name (column_name column_type);CREATE table_name (column_type column_name); PreviousNext

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.