Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Introduction to Object-oriented Analysis and Design Fall 2020 1. (20 points) True or False. Answer either True or False. (a) (2 points) The object-oriented paradigm
Introduction to Object-oriented Analysis and Design Fall 2020 1. (20 points) True or False. Answer either True or False. (a) (2 points) The object-oriented paradigm is a silver bullet in software engineering, according to the conclusion made in the article Does 00 Sync with How We Think? authored by Les Hatton. (b) (2 points) Object-oriented analysis focuses on doing the right thing, and object-oriented design focuses on doing the thing right. (c) (2 points) A mizin is a superclass that provides extra functionality. Its subclass usually does not have a is-a relationship with the mixin class. For example, the MailSender class that provides the method send mail could be a mixin class for the subclass EmailableContact. However, we could not say that EmailableContact is-a MailSender. (d) (2 points) Abstraction is an important mental tool for software design, which enables us to ignore irrelevant details and focus on the most essential aspects of the problem at hand. (e) (2 points) "If it walks like a duck or swims like a duck, it is a duck. Duck typing achieves polymorphism without inheritance and method overriding. (f) (2 points) Monkey-patching can be used to change the behavior of a class met hod. For exam- ple, we can monkey-patch a class method called send email such that it does not send email messages to the real people during testing. (g) (2 points) The template design pattern uses inheritance to achieve the Don't Repeat Yourself design principle. This pattern reduces code duplication and increases code reuse. (h) (2 points) If class QueryTemplate has a single statement raise ToBe Implemented() in its class method construct_sql, then QueryTemplate becomes an Abstract Base Class. The exception class ToBe Implemented could inherit from the built-in class Exception. We are unable to create an object directly from QueryTemplate. However, we are able to define a subclass that inherits from QueryTemplate and override construct_sql in the subclass. (i) (2 points) Multiple inheritance, where a subclass inherits from more than one superclass, is a practice that many expert programmers discourage using, since it may introduce the Diamond Problem. () (2 points) The following code defines a class called tally. An instance of tally is a generator, but not a coroutine. def tally(): score - 0 while True : incr - yield score score incr Introduction to Object-oriented Analysis and Design Fall 2020 2. (10 points) Short answers. Briefly answer the following questions. (a) (2 points) What is information hiding? How is information hiding achieved? (b) (2 points) What is encapsulation? What are the main benefits of encapsulation? (c) (2 points) You will model a student borrower for a university library system. Which the following attributes do you want to ignore? Write down these unnecessary attributes. Blood type. Overdue books. Student ID. Amount of unpaid overdue fine. Phone number. Medical history. (d) (2 points) Name a design pattern that can be used to modify the behavior of an existing function or a class method. (e) (2 points) An object is a collection of data and their associated behaviors. How to make two distinct objects interact? Give one example. Introduction to Object-oriented Analysis and Design Fall 2020 3. (20 points) Autonomous vehicles. You will develop a vehicle brain as well as a central brain that would enable autonomous vehicles to run smoothly on a road. For simplicity, assume that the road has only two lanes, one southbound and another northbound. Also, assume that a vehicle could only go in one direction. A southbound vehicle therefore will not have a collision with a northbound vehicle even if their distance is 0. The vehicle brain will be installed on each autonomous vehicle, and the central brain will be installed on a cloud server. Each autonomous vehicle knows its destination. The vehicle brain keeps asking the following three questions: "where am I?" "what is around me?" and "what should I do next?" Each autonomous vehicle knows its current position, speed, and direction. Each autonomous vehicle must be able to communicate with nearby autonomous vehicles. Each autonomous vehicle can speed up, slow down, or pull the emergency brake, to achieve maximm safety. The central brain obtains the movement information of all autonomous vehicles on the road and broadcasts road conditions (e.g., traffic jams) to all vehicles running on the road. In this question, you are required to use Responsibility-driven Design, in which objects have knowing responsibilities and doing responsibilities. (a) (3 points) What are the essential classes you are going to define? List a few dass names. Draw a class diagram for one of the classes. (b) (3 points) A Class Responsibility Collaborator (CRC) model, which includes a number of CRC cards, is useful for both object-oriented analysis and object-oriented design. What are the three components in each card? (c) (6 points) Draw a complete set of CRC cards for the above-mentioned software (including the vehicle brain and the central brain). Introduction to Object-oriented Analysis and Design Fall 2020 (d) (2 points) What candidate attributes or methods have you excluded (or ignored) in your design, if any? And why? (e) (2 points) Iterative and incremental development (IID). Read the following plot taken from Craig Larman's book Applying UML and Patterns and answer the following question. requirements workshops requirements software requirements software 90% 90% ... 50% 30% 20% 5% 20% 2% Iteration 1 8% 10% Iteration 2 Iteration 3 Iteration 4 Iteration 5 Why is it important to hold four consecutive requirements workshops in the early IID itera- tions? Give a bad consequence if we don't. Introduction to Object-oriented Analysis and Design Fall 2020 (f) (4 points) Autonomous vehicles should be interconnected to share position information, i.e., there should be a pair wise connection between any two autonomous vehicles. Suppose that we use a variant of the observer pattern to model the communication of position information among autonomous vehicles. What is the output of the following code? How is the variant different from the canonical observer pattern, as shown in the next page? class AutonomousVehicle: def -init.-(self, name, direction): self. observers 11 self.name = name self. direction direction Southbound or northbound self-position - 0 def attach( self, observer ): self.observers.append(observer) aproperty def position(self): return self.position a position. setter def position(self, position): self-position - position self-update observers() def .update observers(self): for o in self.obs er vers: o(self) def --call.. (selfother): if self.direction - other direction and abs(self. position - other position)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started