CSE 3901 Final Exam Questions and Answers|
Latest update
, Q1. What does MVC stand for, and what is the responsibility of each
component?
Answer:
MVC stands for Model-View-Controller. The Model represents the
application's data and business logic (e.g., an Active Record class backed by
a database table). The View is responsible for presentation — generating the
HTML/JSON that is sent back to the user. The Controller acts as the
coordinator: it receives incoming requests, interacts with the Model to fetch or
update data, and selects/renders the appropriate View.
Q2. In a Rails request, describe the order in which MVC components are
invoked, starting from the router.
Answer:
1) The router matches the incoming URL/HTTP verb to a controller action. 2)
The Controller action runs, typically calling on a Model to query or modify
data in the database. 3) The Controller then hands data to a View template.
4) The View renders the final response (HTML/JSON/etc.), which the
Controller sends back to the client.
Q3. Why does Rails separate an application into Model, View, and
Controller instead of putting everything in one file?
Answer:
Separation of concerns improves maintainability, testability, and reusability.
Business logic and data access (Model) can change independently of how
data is displayed (View), and the Controller logic that ties them together can
be tested or modified without touching either. It also allows multiple
developers to work on different layers simultaneously and makes it easier to
swap out one layer (e.g., change the View format from HTML to JSON)
without rewriting the Model.
Q4. True or False: In Rails, the View is allowed to directly query the
database using Active Record.
Answer:
False (by convention). Although technically possible, Rails convention
keeps database access inside Models (and orchestrated by Controllers).
Latest update
, Q1. What does MVC stand for, and what is the responsibility of each
component?
Answer:
MVC stands for Model-View-Controller. The Model represents the
application's data and business logic (e.g., an Active Record class backed by
a database table). The View is responsible for presentation — generating the
HTML/JSON that is sent back to the user. The Controller acts as the
coordinator: it receives incoming requests, interacts with the Model to fetch or
update data, and selects/renders the appropriate View.
Q2. In a Rails request, describe the order in which MVC components are
invoked, starting from the router.
Answer:
1) The router matches the incoming URL/HTTP verb to a controller action. 2)
The Controller action runs, typically calling on a Model to query or modify
data in the database. 3) The Controller then hands data to a View template.
4) The View renders the final response (HTML/JSON/etc.), which the
Controller sends back to the client.
Q3. Why does Rails separate an application into Model, View, and
Controller instead of putting everything in one file?
Answer:
Separation of concerns improves maintainability, testability, and reusability.
Business logic and data access (Model) can change independently of how
data is displayed (View), and the Controller logic that ties them together can
be tested or modified without touching either. It also allows multiple
developers to work on different layers simultaneously and makes it easier to
swap out one layer (e.g., change the View format from HTML to JSON)
without rewriting the Model.
Q4. True or False: In Rails, the View is allowed to directly query the
database using Active Record.
Answer:
False (by convention). Although technically possible, Rails convention
keeps database access inside Models (and orchestrated by Controllers).