Sit771-7 1P
Sit771-7 1P
Sit771-7 1P
Focus
• Concept
Focus on learning diverse Object-Oriented Programming (OOP) principles, including inheritance,
abstraction, and polymorphism, understanding their applications, methodologies, and contextual
relevance in software development.
• Process
Focus on instilling crucial skills like modular and efficient code design, a solid understanding of
object-oriented principles, and the ability to minimize code duplication preparing yourself for
collaborative, maintainable, and scalable software development practices.
Overview
For this task, we’re going to take a look at creating an abstract Transaction class, which our Withdraw,
Deposit and Transfer will inherit from. Doing this will reduce code duplication and allow us to simplify
code in certain areas of our program!
Submission Details
1. Create a new C# file named Transaction.cs , in it, add the Transaction class. Here is the
UML diagram for the transaction class:
The # symbol represents protected : a new scope modifier that means this class member is
available within this class and any child classes, but not other classes.
Add the protected decimal amount field, and the private DateTime _dateStamp ,
bool _executed , and bool _reversed fields.
Implement the abstract readonly property for Success and the other properties.
Add a constructor that sets the value of the _amount field.
Add the abstract Print() method. This will be a placeholder that the different
transactions will override and provide details for.
Add the virtual Execute() method. It should perform the following steps:
Add the virtual Rollback() method. This should operate in a similar way to Execute
The main details of these classes will not change, so you only need to set these up to workwith the
new Transaction class. There should not be large changes needed.
The constructor’s should call the base class constructor, passing up the amount, and then in
its body it will assign the _account (s) as necessary.
Transfer will need two private account fields, the _toAccount and the
_fromAccount which should be assigned in the Transfer constructor.
For example:
Implement Print (overriding the abstract method from the Transaction class).
Now that our three types of transactions are all inherited from the Transaction class, we can store
a list of transactions in the accounts and in the bank!
4. Check your Program class and make sure that the Transactions (DepositTransaction,
WithdrawTransaction, and TransferTransaction) are all being called on your Bank object.
6. Run your program and upload a screenshot to OnTrack alongside the program files.
Task Discussion
For this task, you need to discuss the use of inheritance and polymorphism in object-oriented solutions: