Download CPSC 2150 EXAM 1 QUESTIONS LATEST UPDATE 2024/2025 WITH 100% DETAILED VERIFIED ANSWERS and more Exams Business Administration in PDF only on Docsity! CPSC 2150 EXAM 1 QUESTIONS LATEST UPDATE 2024/2025 WITH 100% DETAILED VERIFIED ANSWERS Who is responsible for making sure that the precondition of a function is met? The client that calls the function Who is responsible for making sure that the post-condition of a function is met? The implementer of the function Is it a good practice to have each function start with an if statement that checks to make sure the preconditions are true? False True or False? The precondition automatically checks and enforces itself by checking the value of the parameter, and returning an error if the parameter is incorrect. False How does the concept of information hiding help keep our data secure? Making attributes privates and only allowing access through public method controls limits access to data. If data is changes, it must go through a method where there is control over accepted values How does the concept of Separation of Concerns make it easier for our program to adapt to change? It separates the program into modules. This allows specific parts of the program to easily found and revised. It also allows the user to to separate different programs into areas in which are important. Is is safe to assume the invariant of a class is true at the beginning of a private method? No Is is safe to assume the invariant of a class is true after the constructor for the object has been completed? Yes Is is safe to assume the invariant of a class is true after a private method has finished? No Is is safe to assume the invariant of a class is true during the body of a public method? No Is is safe to assume the invariant of a class is true when the object has been declared, but not initialized? No Is is safe to assume the invariant of a class is true at the beginning of a public method? Yes Is is safe to assume the invariant of a class is true during execution of a private method? No Is is safe to assume the invariant of a class is true after a public method has finished? Yes Which of the following can be the declared data type (syntactically allowed by the compiler, not best practice) a. An interface type b. A class type c. A primitive type Objects and classes Component providers are _________ Ex. write a function Implementers Users of the components are _________ ex. write code that calls a function client The (implementer or client?) writes the function implementer The (implementer or client?) writes codes that calls the function client Characterizes the responsibility of the client that calls the operation Precondition (requires clause) Characterizes that responsibility of the code that implements that operation Post condition (ensures clause) Who's responsibility is it to ensure precondition is met? client (writes codes that calls the function) Are always true (kinda) and must always be enforced Usually refer to some property of a variable in a class Invariant Who defines the invariant? Implementer of the class Can be accessed only by instances of the same class Provide concrete implementation/representation Private members Can be accessed by any object Provide abstract view (client-side) Public members Who are the postconditions and preconditions meant for? client Who is the invariant meant for? The implementer Represent interactions between the system and it's users (exists to create a connection not encapsulate data) ex. user interface, scanner object Boundary objects Are responsible for the actual flow of the program (handles interactions between boundary and entity objects) Makes sure events happen in a certain order ex. main Control object Place to specify a contract and it provides a separation of concerns between class uses and implementer Interface What visibility can interfaces have? Public and package visible Can constructors be in a interface? No Declare a class that implements that interface... Employee - class Salaried - interface class Employee implements Salaried { ... } How to define interface methods in class? return type - void function name - setSalary parameter - BigDecimal public void setSalary (BigDecimal d) { ... } Can interfaces be instantiated? No, don't have constructors ex. interface is Salaried Salaried payee = new Salaried(); created a compile time error Set at compile time declared type set at run time (by new) Dynamic type Sates what will be true after initialization (after constructor) Initialization ensures States what allows us to define some concepts for specification allows to hint at private variables must be generic and abstract