Homework
2 Details for MPCS 5141
Each
homework assignment will consist of a small problem in some OO
code, which is somehow problematic, given your developing
understanding of good OO best practices and patterns, you will
improve, thus eliminating any negative issues in the code you
are given. Each homework assignment is intended to give every
student hands-on experience with the core concepts covered
during the course. You may code your solution to the
problem in any legitimate OO language of your choice. You
need to submit labs to the TAs for grading--see submission
instructions below. Generally, unless otherwise specified,
you will have one week to complete each assigned homework
problem.
See
the
syllabus for information on grading. Turning in lab
assignments on time is required, without exception, and all late deliveries will be
penalized, regardless
of cause. Submit your assignments to the
subversion repository according to the directions on the
syllabus page.
You
may
write these solutions in any programming language of
your choice. Our suggestion is now is not the time to
learn a new programming language along with the concepts
themselves. So our suggestion is to use whatever
programming language you know best.
Homework
2 Due: 5:00 pm, Monday,
February 15, 2021
Coding
Problem:
BACKGROUND:
Like
all programming-related problems, learning a new programming
language or style is not an exercise in reading but rather an
exercise in thinking and typing. This homework is designed
to give you hands-on experience in some fundamental skills
involved in object-oriented design and coding. You will
generally find the References section below helpful in addition
to the required and recommended reading.
WHAT YOU NEED TO DO:
See the code here. You
are to read and understand the code, what it is intending to
accomplish, and what the responsibilities are of the class or
classes. Nonetheless, there are one or more problems in the
code which require your insight in their amelioration. Your
mission, should you choose to accept it, is to "fix" the
problem(s) in the code, without introducing any new problems, by
coding a replacement set of code in any legitimate object-oriented
programming of your choice. Be sure to include a README with
instructions on how to compile (if necessary) and run your coded
solution.
Very important: Inside comments at the top of your
coded solution, you are to fully describe the problem(s) in the
original code as you have determined it, and describe why your
solution eliminates the original problem(s).
Step One:
By examining the code, you discover that
this C# code implements a shopping cart in an online
Etailer. It allows for a few different types of payment
methods: a customer can pay with paypal or with a credit
card (the actual implementations of paypal and cc are stubbed
out). Fine. That's all there was way back in
2001. You of course didn't write this code. A guy who
no longer (and for good reason!) works for the company, named
Gerald, wrote this slop. Then, yesterday, your boss came to
you and said there's this new payment she wants to accept, called
ApplePay, and told you to implement it by updating the
CallShoppingCart() method in the ShoppingCart. (Your boss
doesn't actually write code, truth be told, although she has
crafted a few compelling Excel macros. She has her MBA from
Harvard Business School. But she knows she's a genius and
how hard can this be? She's been through Agile training and knows that this
can be done quickly and easily if you just welcome change and
keep it simple. So she's kind enough to share her
wisdom and experience with you by telling you how to fix this
problem.)
You spent the evening last night eating pizza from Pizza Capri and
researching ApplePay. This morning, just a minute ago, she
came to you, unbelievably, and says she now wants to accept, in
addition to ApplePay, something called SEPA, as well as
cryptocurrencies like Bitcoin (OMG!). I told you she was a
genius. Tomorrow, you fully expect her to come in with some
new payment method you've never even heard of. Such are the
vicissitudes of life.
Now, you can, if you wish, implement SEPA and Cryptocurrency
support by adding some new "else if" statements in
CallShoppingCart if you want. That's certainly what Gerald
would have done. It's what The GeniusTM wants you
to do. But you're smarter than that. You know if you
add a few new "else if" statements, that's your future passing
before you in a flash. No. You want to modify
CallShoppingCart so you never have to ever touch that code
again. Ever. No matter how many new
methods of payment show up.
Step Two:
Write a replacement set of code
in any legitimate object-oriented programming of your choice,
rewriting CallShoppingCart() (and associated stub functions) so
that it is more generic and will support any new form of payment
method that comes along in the future. Then stub in the
ApplePay and SEPA and Bitcoin payments. And no, you do not
have to actually code the implementation of bitcoin payments, just
stub them all out in your replacement version of the code.
References:
You
may
find the following references helpful:
https://en.wikipedia.org/wiki/Strategy_pattern
https://en.wikipedia.org/wiki/Open–closed_principle
Submitting:
Use the
folder named "hw2" in your Subversion repository. See the
syllabus for more info about submission using Subversion. Upload
your HW2 solution file(s) and any supporting materials to the
repo.