Điểm của bài asm còn tùy thuộc vào người chấm. Chỉ cần paraphase bài này là có thể đạt merit hoặc có thể đạt distinction tùy vào thầy dạy. 1 trong nhưng tool paraphase mình recommend là quillbot.ASSIGNMENT 1 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20 Advanced Programming Submission date Date Received 1st submission Re submission Date Date Rec. ASSIGNMENT FRONT SHEET Qualification BTEC Level HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date Date Received 1st submission Resubmission Date Date Received 2nd submission Student Name Student ID Class Assessor name Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism I understand that making a false declaration is a form of malpractice Student’s signature Grading grid P1 P2 M1 M2 D1 D2 Summative Feedback: Grade: Lecturer Signature: Resubmission Feedback: Assessor Signature: Date: Table of Contents A INTRODUCTION B OOP GENERAL CONCEPT a) WHAT IS OOP OOP Introduction General Concept of OOP Object and Class in OOP Pros and Cons of OOP b) APIE Inheritance Abstraction 10 Encapsulation 10 Polymorphism 11 c) SOLID 11 S Singleresponsibility Principle 11 O Openclosed Principle 12 L Liskov Substitution Principle 12 I Interface Segregation Principle 12 D Dependency Inversion Principle 12 C OOP SCENARIO 12 3.1 Scenario 12 3.2 Use case Diagram 14 3.3 Class Diagram 19 D Design Patterns 21 Importance of Design Pattern: 21 When to use Design Patterns: 21 4.1 Creational pattern 22 Description of a creational scenario 26 4.2 Structural pattern 28 Description of a structural scenario 32 4.3 Behavioral pattern 34 Description of a behavioral scenario 43 E Design Pattern vs OOP 45 F Conclusion 46 References 46 List Of Tables Table 1: StartGame Usecase 15 Table 2: PlayGame use case 16 Table 3: Change Setting Usecase 17 Table 4: View Records usecase 17 Table 5: Exit Usecase 18 Table 6: Ingame menu usecase 19 List Of Figures Figure 1: OOP Introduction Figure 2: OOP Concept Figure 3: Inheritance Example Figure 4: Abstraction Example 10 Figure 5: Encapsulation Example 11 Figure 6: Polymorphism Example 11 Figure 7: Usecase for Scenario 14 Figure 8: Class Diagram for scenario 19 Figure 9: Apstract Factory 23 Figure 10: Factory Method 24 Figure 11: Builder Pattern 24 Figure 12: Prototype Pattern 25 Figure 13: Singleton Design Pattern 26 Figure 14: Class diagram of creational scenario 27 Figure 15: Adapter Pattern 28 Figure 16: Brigde Pattern 29 Figure 17: Composite Design pattern 29 Figure 18: Decorator Design Pattern 30 Figure 19: Facade Design pattern 31 Figure 20: Flyweight Design Pattern 31 Figure 21: Proxy Design pattern 32 Figure 22: Class diagram of structural Scenario 33 Figure 23: Chain of Responsibility 34 Figure 24: Command Design pattern 35 Figure 25: Interpreter Pattern 36 Figure 26: Iterator Design Pattern 37 Figure 27: Mediator Pattern 38 Figure 28: Memento Design Pattern 38 Figure 29:Observer Design Pattern 39 Figure 30: State Design Pattern 40 Figure 31: Strategy Design pattern 41 Figure 32: Template Method design pattern 42 Figure 33: Visitor Design Pattern 43 Figure 34: Class Diagram of Behavioral Scenario 44 A INTRODUCTION A design pattern is a reusable solution for common problems in software design with a specific circumstance A design pattern is a blueprint that cannot be converted into source code Typically, objectoriented design patterns depict relationships and interactions between classes or objects but not specify the classes or objects involved in the final application This is a report about objectoriented paradigms and design patterns First, we will learn about OOP and the general concepts of OOP Next, we will analyze in detail a situation related to OOP Design patterns will be introduced and analyzed its general concepts The article will compare and analyze the relationship between objectoriented paradigms and design patterns Finally, we will design and build class diagrams using a UML tool B OOP GENERAL CONCEPT a) WHAT IS OOP OOP Introduction Figure 1: OOP Introduction With the launch of Simula in the mid1960s, OOP principles initially appeared, and they expanded further in the 1970s with the introduction of Smalltalk Objectoriented methods evolved even though software developers did not adopt early breakthroughs in OOP languages In the mid1980s, there was a resurgence of interest in objectoriented methods OOP languages, C++, and Eiffel have grown popular among mainstream computer programmers Throughout the 1990s, OOP increased in prominence, most notably with the launch of Java and the enormous following it acquired Furthermore, in 2002, in conjunction with the release of the NET Framework, Microsoft launched C (pronounced Csharp), a new OOP language, and a redesign of their hugely popular existing language, Visual Basic, to make it fully objectoriented OOP languages are still popular today and play a significant role in contemporary programming (Alexander S Sarah Lewis, 2017) General Concept of OOP Figure 2: OOP Concept Objectoriented programming is a way of creating software in which the structure is built on objects interacting with one another to achieve a goal As part of this interaction, messages are sent between the objects An object can act in response to a message OOP is a programming technique that allows programmers to create objects in code that abstracts reallife objects This approach is now successful and has become one of the paradigms for software development, especially for enterprise software During the development of OOP applications, classes will be defined to model actual objects These classes will be executed as objects When users run the application, the methods of the object will be called The class defines what the object will look like: what methods and properties will be included An object is just an instance of the class Classes interact with each other by the public API: a set of methods, and its public properties The goal of OOP is to optimize source code management, increase reusability, and most importantly, help encapsulate procedures with known properties using objects (Alexander S Sarah Lewis, 2017) Object and Class in OOP 3.1 Class In OOP, a class is frequently understood as a blueprint for creating objects (a specific data structure), providing initial values and constructors for the nature (instance variables or attributes), and defining and implementing behaviour (member functions or methods) Classes are used to generate and manage new objects, as well as to facilitate inheritance, which is a crucial component of objectoriented programming and a technique for code reuse (Oracle, 2012) 3.2 Object A class instance is an object In OOPS, an object is a selfcontained component with methods and attributes that make a specific type of data usable An object in OOPS might include a data structure, a variable, or a function from a programming standpoint It has a memory area set aside for it Pros and Cons of OOP 4.1 Pros OOP models complex things as simple structures Reusable OOP code, which saves resources It makes debugging easier Compared to finding errors in many places in the code, finding errors in (prestructured) classes are more straightforward and less timeconsuming High security, protecting information through packaging Ease of project expansion 4.2 Cons Make data processing separate When the data structure changes, the algorithm must be modified OOP does not auto initialize and release dynamic data, and it does not accurately describe the actual system b) APIE Inheritance In OOP, inheritance is used to classify objects in your programs based on shared characteristics and functions Working with objects becomes more accessible and more intuitive as a result It also facilitates programming by allowing you to combine typical characteristics into a parent object and inherit these characteristics in child objects (Alexander S Sarah Lewis, 2017) This is a feature commonly used in software development Inheritance allows creating a new class (Child class), inheriting, and using properties and methods based on the parent class The Child classes inherit all the Parent class components Subclasses can extend the components or add new ones (Nitendratech, 2018) Example: There are many types of vehicles In this case, the Vehicle can be considered as the base class with properties color, wheel, engine, weight and actions Start, Stop, Turn “Car” and “Motorbike” are two derived classes that inherited from the base class Both classes inherit all attributes and actions from the base class but “Car” also contains action Reverse and “Motorbike” contains action kickstand Figure 3: Inheritance Example Guns will increase plane damage Light gun: + damage (free) Standard gun: + damage (50000 points) Heavy gun: + damage (200000 points) Legendary gun: + damage (1000000 points) Engine will increase plane speed Standard engine: + 10 speed (free) Double engine: + 20 speed (100000 points) Space engine: + 30 speed (500000 points) Support plane: Depending on the type of aircraft supporting it, it will have different functions Trinity: increase health, damage and 30 speed for player main plane when active (5000000 points) Blood thirster: heal health after taking down an enemy heavy aircraft when active (5000000 points) Figure 22: Class diagram of structural Scenario Explanation The base Plane Abstract class defines properties, methods for the subclass as well as some methods (GetDecription, ) that these concrete decorators can alter These concrete classes (Conqueror, Flash, Sky Doom) provide these default implementations of the properties and methods The PlaneDecorator class extends the Plane class as the other components The primary intent of this class is to clarify the wrapping for all concrete decorators (Lightgun, HeavyGun, Light Amor) The default implementation of the wrapping code includes the _plane (DataType: Plane) property for storing a wrapped plane and the means to declare it The _plane variable should be accessible to the sub decorator classes, so its necessary to make this variable with the protected access modifier This class also delegates work to concrete decorator classes These concrete decorator classes (Lightgun, HeavyGun, Light Amor ) extendthe base decorator functionality and modifying the component behavior accordingly of the plane Decorator class 4.3 Behavioral pattern These design patterns are all about Classs object communication Behavioral patterns are those patterns that are most specifically concerned with communication between objects Behavioral Pattern Include: Chain of responsibility: A way of passing a request between a chain of objects Sender transmits a request to a chain of objects in chain of responsibility Any item in the chain can handle the request Avoid tying the sender of a request to its recipient by giving different objects a chance to handle the request, according to the Chain of Responsibility Pattern In the process of dispensing money, an ATM, for example, employs the Chain of Responsibility design pattern (sourcemaking, n.d.) Figure 23: Chain of Responsibility ImageCre: Chain of responsibility design pattern RefactoringGuru To put it another way, each receiver generally contains a reference to another receiver If one object is unable to process the request, it is sent to the next recipient, and so on Advantage of Chain of Responsibility Pattern It decreases coupling While assigning duties to objects, it offers flexibility It lets a group of classes function as if they were one; events generated by one class may be passed to other handler classes via composition Usage of Chain of Responsibility Pattern: When a request can be handled by more than one object and the handler is uncertain When a group of objects capable of handling a request must be dynamically provided Command: Encapsulate a command request as an object According to the Command Pattern, Encapsulate a request in an object and deliver it to the invoker object as a command The invoker object searches for a relevant object that can handle this command and passes the command to that object, which then performs the command Figure 24: Command Design pattern ImageCre: Command Design Pattern Stackoverflow Advantage of command pattern: It distinguishes between the object that executes the action and the object that invokes it Because current classes arent modified, its simple to add new commands Usage of command pattern: When you need to parameterize, objects based on an action When many requests must be created and executed at separate times When rollback, logging, or transaction functionality is required Interpreter: A way to include language elements in a program To define a representation of grammar of a particular language, as well as an interpreter that uses this representation to interpret sentences in the language, according to an Interpreter Pattern In general, the Interpreter pattern can only be used in a restricted number of situations The Interpreter pattern can only be discussed in terms of formal grammar, although there are superior solutions in this field, which is why it is not often utilized Figure 25: Interpreter Pattern ImageCre: Interpreter Pattern Baeldung Advantage of Interpreter Pattern It is less difficult to modify and expand the grammar Its simple to put the grammar into practice (sourcemaking, n.d.) Iterator: Sequentially access the elements of a collection Provide a method for progressively accessing the constituents of an aggregate object without revealing its underlying representation The traversal of a collection should be elevated to full object status. traverse with polymorphism Figure 26: Iterator Design Pattern ImageCre: Iterator Pattern RefactoringGuru Advantage of Iterator Pattern It allows you to traverse a collection in different ways It streamlines the collections user interface Usage of Iterator Pattern: When you need to get a hold of a group of things without revealing their internal representation When many traversals of items are required, the collection must be able to accommodate them Mediator: Defines simplified communication between classes To define an entity that captures how a group of objects communicate, states the Mediator Pattern Ill demonstrate the Mediator pattern by examining an issue When we first start developing, we have a few classes that interact with one another to produce outcomes Consider how, as functionality develops, the reasoning becomes more complicated So, what happens next? We added additional classes, and they still communicate, but maintaining this code is becoming increasingly tough As a result, the Mediator pattern solves this issue (sourcemaking, n.d.) Figure 27: Mediator Pattern ImageCre: Mediator Pattern DotNetTutorials The mediator pattern is intended to simplify communication across various objects or classes This technique creates a mediator class that generally handles all communication between distinct classes and makes the code easier to maintain Memento: Capture and restore an objects internal state To restore the state of an item to its prior state, according to a Memento Pattern However, it must so without breaking Encapsulation In the event of a mistake or failure, such a scenario is beneficial Token is another name for the Memento pattern Figure 28: Memento Design Pattern ImageCre: Memento Desine Pattern RefactoringGUru One of the most often used operations in an editor is undo, sometimes known as backspace or ctrl+z The undo action is implemented using the Memento design pattern This is accomplished by storing the objects current state as it changes Observer: A way of notifying change to a number of classes Just construct a onetoone dependence so that when one object changes state, all its dependents are alerted and changed immediately, according to the Observer Pattern Dependents or PublishSubscribe are other names for the observer design Figure 29:Observer Design Pattern ImageCre: Observer DesignPattern SourceMaking Benefits: It explains the interaction between the observer and the objects It allows for broadcaststyle communication to be supported Usage: When a state changes in one item must be mirrored in another without the objects being tightly connected When we design a framework that will be updated in the future with additional observers with few changes (sourcemaking, n.d.) State: Alter an objects behavior when its state changes The class behavior changes dependent on its state, according to a State Pattern We generate objects that represent distinct states and a context object whose behavior changes as its state object changes in State Pattern Objects for States is another name for the State Pattern Figure 30: State Design Pattern ImageCre: State Design Pattern Advantages: It preserves statespecific behavior Any state transitions are made explicit Usage: When an objects behavior is dependent on its state and it has to be able to adjust its behavior at runtime to match the new state Its utilized when there are a lot of multipart conditional statements in the actions that are dependent on the state of an object Strategy: Encapsulates an algorithm inside a class Defines a family of functions, encapsulates each one, and makes them interchangeable, according to a Strategy Pattern Policy is another name for the Strategy Pattern Figure 31: Strategy Design pattern ImageCre: Strategy Design Pattern Sourcemaking Benefits: It may be used instead of subclassing Each behavior is defined within its own class, removing the need for conditional expressions It makes it easy to add new functionality without having to rewrite the program Usage: When many classes differ simply in their behaviors, this is used When multiple variants of an algorithm are required, it is utilized Template method: Defer the exact steps of an algorithm to a subclass In an operation, define the skeleton of an algorithm while deferring some stages to client subclasses Subclasses can rewrite some phases of an algorithm using the Template Method without affecting the algorithms structure Figure 32: Template Method design pattern ImageCre: Template Method Source Making Algorithm placeholders are declared in the base class, and the placeholders are implemented in the descendant classes Strategy is similar to Template Method in terms of granularity Inheritance is used in the Template Method to alter parts of an algorithm Delegation is used in strategy to change the whole algorithm Individual objects logic is altered by strategy The Template Method affects the entire logic of a class Template Method is a subset of Factory Method (Anon., 2022) Visitor: Defines a new operation to a class without change Represent an operation that will be executed on an object structures components Without modifying the classes of the components on which it acts, Visitor allows you to specify a new operation The traditional method for restoring type information that has been lost, Figure 33: Visitor Design Pattern ImageCre: Visitor Pattern SourceMaking Based on the two types of items, take the appropriate action Interpreters abstract syntax tree is a Composite (therefore Iterator and Visitor are also applicable) A Composite can be traversed by an Iterator Over a Composite, a visitor can perform an operation Because the visitor can begin whatever is suitable for the type of item it meets, the Visitor pattern is similar to a more powerful Command pattern (Javatpoint, n.d.) Description of a behavioral scenario In Greenwich, while the current semester isnt finished yet, students will immediately receive notification of paying tuition fees for the next semester Tuition Fees could be paid online via various emoney transfer platforms: VieettelPay, DNG bankDebit card, and TPbank Students can check the transaction cost of the payment via the payment tuition fee online With paying via Viettel Pay, go to Viettel Pay App, verify the Viettel phone number and Select FPT tuition payment Enter student code and perform pay the tuition fee The transaction fee of Viettel pay is free With DNGbank, the necessary info is the information on the bank card (Name, card number, Expired date) The DNGBank’s transaction fee is 3300 vnd The other is the DNGDebit payment method, its necessary info also the information on the Debit Card (Name, Card number, CVV and expired date) The transaction of this payment method is 1,4% of the tuition fee + 3300 vnd Figure 34: Class Diagram of Behavioral Scenario Explanation: The GWPayingTuitionFeeOnline accepts IPayingTuitionFeeStrategy object through the constructor The GWPayingTuitionFeeonline does not know the concrete classes of this strategy But It could work with all strategy classes through the IPayingTuitionFeeStrategy interface IPayingTuitionFeeStrategy Interface for strategy pattern in this case to pay tuition fee, the student object passed as an argument These concrete classes implement the IPayingTuitionFeeStrategy Interface to implement algorithms for paying tuition fees using DNGdebit, DNGbank or via Viettelpay Concrete Strategies (ViettelPayStrategy, DNGBankStrategy, DNGDebitStrategy) implement the algorithm while implementing the IPayingTuitionFeeStrategy interface This interface helps these concrete strategy classes interchangeably This solution delegates the selection of payment method to the Strategy object instead of implementing multiple versions of the algorithm on its own The selection of the algorithm defined by these concrete strategy classes will be called via the IPayingTuitionFeeStrategy interface E Design Pattern vs OOP The concepts of OOP provide design patterns, which assist to build OOP more effectively and adapt to scenarios It will take much longer to run the program or address difficulties if you dont use a design pattern Design patterns can make your code more reusable and adaptable, allowing you to include any function that fulfills the criterion (Techopedia, 2011) For example, when a car is created, there are only doors, engine, wheels But what will happen when owners take their car to a modification garage to add more features (body kit, spoiler, sticker) The simplest way to solve that problem is extend the base class and create a bunch of subclasses or create a massive constructor with lots of unused parameters In this case, the builder design pattern helps the user to execute these steps of the builder You can create various builder classes with the same set of builder steps set but in a different manner Another example that can be applied is vehicle painting The simplest way is creating a Vehicle class and pairs of subclasses such as Car and Motorbike To create colored vehicles in red and green, users need to create a bunch of subclasses such as GreenCar, RedCar, GreenMotorbike, RedMotorbike Problems will occur if users decide to add a few more colors By switching from inheritance to object composition, the Bridge pattern tries to tackle this problem The colorrelated code can be extracted into its own class with two subclasses: Red and Green The Vehicle class then receives a reference field that points to one of the color objects Any colorrelated tasks can now be delegated to the connected color object by the shape This reference will serve as a bridge Design pattern is not a design that can be transferred directly into code, it Is only a description of way to solve many problems in many situations Even without the specification of class and object, design pattern illustrates the relationship of classes on objects and how they interact Theres always occurs problem when programming and various ways to solve it, but it maybe not be optimal choice Design patterns are created to handle an issue in the most efficient way possible, with solutions available in OOP programming and most modern programming languages F Conclusion The report covered ideas and features of ObjectOriented Programming (OOP), as well as how to apply OOP in practice with considerable scripting Explain the systems activities and behavior for the scenario described in the research using two use case diagrams (use case diagram, class diagram) We may learn the foundations of OOP and its concept through this report Weve also detailed the general definitions and features of three different types of design patterns: structural, creational, and behavioral patterns Each one includes a class diagram, activity, and explanation to show how design patterns and OOP are related This can assist us improve our programming language approach and make our project run more smoothly This report can also serve as a foundation for future reports References Alexander S Sarah Lewis, 2017 objectoriented programming (OOP) Online Available at: https:www.techtarget.comsearchapparchitecturedefinitionobjectorientedprogrammingOOP Anon., 2022 Refactoring.Guru Online Available at: https:refactoring.gurudesignpatterns Anon., n.d Online Available at: https:topdev.vnblogsolidlagi?fbclid=IwAR2UzzITTxPd3eXG7b4kpG40kJYj3pMs_kSnYo30wjPlMlo61F8A4pveS80:~:text=L%E 1%BA%ADp%20tr%C3%ACnh%20h%C6%B0%E1%BB%9Bng%20%C4%91%E1%BB%91i%20t%C6 %B0%E1%BB%A3ng,t%C6%B0%E1%BB%A3ng%20trong%20th%E1%BA%BF%20gi%E1%BB%9Bi % Anon., n.d FULL STACK DEVELOPER Online Available at: https:devfull.me HOÀNG, P H., 2015 Online Available at: https:toidicodedao.com20150324solidlagiapdungcacnguyenlysoliddetrothanhlaptrinhviencodecung?fbclid=IwAR2hOXf9Dg_V_H8TfeyD3A5md2fri6nQZVMqTA3QEM6zJBKsdHflZnylBo Javatpoint, n.d Design Pattern Online Available at: https:www.javatpoint.comdesignpatternsinjava Mui, Nguyen Van, 2018 Online Available at: https:viblo.asiapsolidtrongandroidORNZqPmnK0n Nitendratech, 2018 ObjectOriented Programming concepts Online Available at: https:www.nitendratech.comprogrammingobjectorientedprogramming Oloruntoba, S., 2020 Online Available at: https:www.digitalocean.comcommunityconceptual_articlessolidthefirstfiveprinciplesofobjectorienteddesignliskovsubstitutionprinciple Oracle, 2012 Object Class Definitions Online Available at: https:docs.oracle.comjavasejnditutorialldapschemaobject.html Shvets, A., 2021 Dive Into DESIGN PATTERNS s.l.:s.n sourcemaking, n.d behavioral patterns Online Available at: https:sourcemaking.comdesign_patternsbehavioral_patterns sourcemaking, n.d structural patterns Online Available at: https:sourcemaking.comdesign_patternsstructural_patterns Techopedia, 2011 Design Pattern Online Available at: https:www.techopedia.comdefinition18822designpattern TopDev, 2019 SOLID gì? Áp dụng SOLID để trở thành lập trình viên giỏi Online Available at: https:topdev.vnblogsolidlagi Tutorial, O., n.d Object Class Definitions Online Available at: https:docs.oracle.comjavasejnditutorialldapschemaobject.html W3schools, n.d C++ OOP Online Available at: https:www.w3schools.comcppcpp_oop.asp ... https:topdev.vnblogsolidlagi?fbclid=IwAR2UzzITTxPd3eXG7b4kpG40kJYj3pMs_kSnYo30wjPlMlo61F8A4pveS80:~:text=L%E 1% BA%ADp%20tr%C3%ACnh%20h%C6%B0%E1%BB%9Bng%20%C4% 91% E1%BB%91i%20t%C6 %B0%E1%BB%A3ng,t%C6%B0%E1%BB%A3ng%20trong%20th%E1%BA%BF%20gi%E1%BB%9Bi % Anon.,... Abstraction 10 Encapsulation 10 Polymorphism 11 c) SOLID 11 S Singleresponsibility Principle 11 O Openclosed Principle... Example 10 Figure 5: Encapsulation Example 11 Figure 6: Polymorphism Example 11 Figure 7: Usecase for Scenario 14 Figure 8: Class
Trang 1ASSIGNMENT 2 FRONT SHEET
Qualification TEC Level 5 HND Diploma in ComputingUnit number and title Unit 20: Advanced Programming
Submission date 30/06/2022 Date Received 1st submission
Trang 2 Summative Feedback: Resubmission Feedback:
Internal Verifier’s Comments:
Signature & Date:
Trang 3Table of Contents
A INTRODUCTION 5
B SCENARIO ANALYSIS 6
1 SCENARIO 6
2 DIAGRAM 6
2.1 Use-case Diagram 7
2.2 Class Diagram 10
C IMPLEMENTATION 16
1 Code(Related to Class Diagram) 16
1.1 Loan Concrete Class 16
1.2 Client Concrete Classes 22
1.3 Credit Checker Classes 24
1.4 Loans Factory Method Design Pattern Classes 27
2 Code(Some Represented Codes in GUI) 31
3 Program ScreenShots 35
D DISCUSSION 40
1 Range of Similar Patterns 40
1.1 Briefly Summary of Some Similar Design Patterns to Factory Method 40
1.2 Explain Why Factory Design Pattern is The Most Suitable for this Scenario 41
2 Usage of Patterns 43
References 44
List of Table Table 1: Signup usecase 8
Table 2: MakeLoan usecase 8
Table 3: View Profile usecase 9
Table 4: Logout Usecase 10
Trang 4List of Figures
Figure 1: Use-case diagram 7
Figure 2: Class Diagram 10
Figure 3: Loans Concrete Classes 11
Figure 4: Client Concrete Class 12
Figure 5: Loans Factory Method Design Pattern 14
Figure 6: Credit Checker Classes 15
Figure 7:Enum 15
Figure 8: Loans CLass 16
Figure 9: HotLoans Class 17
Figure 10: Unsecured Loan Class 18
Figure 11: Overdraft Loan Class 19
Figure 12: InstalmentLoan Class 20
Figure 13: MortgageLoan class 21
Figure 14: User Class 22
Figure 15:Bank Class 23
Figure 16: Item class 24
Figure 17: ICreditChecker interface 25
Figure 18: FastCreditChecker Class 25
Figure 19: ComplexCreditChecker class 26
Figure 20: ServiceChecker Class 26
Figure 21: AutomaticChecker Class 27
Figure 22: ILoanFactory Interface 28
Figure 23: HotLoanFactory Class 28
Figure 24: UnsecuredLoanFactory Class 29
Figure 25: OverdraftLoanFactory Class 29
Figure 26: InstalmentLoanFactory Class 30
Figure 27: MortgageLoanFactory Class 31
Figure 28: Main Form Typical Snippet code 32
Figure 29: AvailableLoanService Form Snippet Code 33
Figure 30: MortgageLoan Form 34
Figure 31: Home Form of app 35
Figure 32: Home Form when unlocking other functions 36
Figure 33: Loan Services Form 37
Figure 34: Profile form 37
Trang 5A INTRODUCTION
In programming, when faced with some problems which are related to OOP or class family organisation, one of the
solutions which would be helpful is the design pattern Design patterns are understood as all-purpose, repeatable
solutions to issues that crop up frequently The best practices are those that seasoned developers follow Patterns are
not entire pieces of code, but they may be used as a model to solve a particular issue Patterns may be used to
compare design problems in any domain since they are reusable
To get more understandable, this report will present the development of the "GetH1gh" application, which has the
problem related to the initialization of an instance of the class and this will be solved by one of the creational
patterns The detailed processing, designing, coding and explaining will be presented below The report also provides screenshots for illustrations and analysis as well as evaluates the most suitable design pattern
Trang 6B SCENARIO ANALYSIS
1 SCENARIO
"GetH1gh" is a relatively famous financial aid office recently, their slogan is wishing to change its approach to finance, helping people have a better life by providing quick - easy - transparent service Now, when being legalized after operating the long outlaw period, "GetH1gh" is planning to develop an online finance application that will help its customers to make loans more straightforward or even create a mortgage loan package online The online financial application of "GetH1gh" has not been completed yet and is being tested with one of its main functions, which is to initiate loan packages Specifically, there are five primary loan packages of
"GetH1gh" including unsecured loans; overdraft loans; instalment loans; mortgage loans and hot loans Each loan also has its own distinct features:
The unsecured loan package will have the highest interest rate is fixed at 21%/year and does not require any collateral Additionally, the procedures for an unsecured loan are quite simple and the credit
For overdraft, it loan limit will be based on the balance of the customer's bank account and the liability and interest of the overdraft will be calculated based on the outstanding balance and the time of the debit The overdraft package could have collateral or not, if there is any collateral to make an overdraft loan, the interest rate of it will decrease significantly
Installment loans will need to declare the items to be paid in instalments, the interest rate is based on the term that the customer will deal with the office The amount and prepayment also will be calculated automatically based on the instalment item
The mortgage loans may need documents of the collateral as well as the loan purpose In case the mortgage collateral has no proven document, the interest rate will be pretty high The loan limit of a mortgage loan is 170 % of the total value of the collateral
Lastly, the special Loan package of "Geth1gh" is a hot loan, its procedures are very simple However, its interest rate is very high
Because of the incompetence of their dev team, our team was invited to assist them in developing this functionality
2 DIAGRAM
Trang 72.1 Use-case Diagram
Here is the use case of entire the program
Figure 1: Use-case diagram
Explanation:
Description: This use case describes the process of Signing up the new user’s
data
Pre-conditions: The user had to download and install this application;
Post Conditions: The system handles and stores the data of the input from the
4) System stores and handle the data from the user 5) Finish
Alternative Course:
Exception: Application is no longer approved for use(occurs at step 1);
Trang 8 Crashing;
Requirements: The appropriate of the system and user;
Table 1: Signup usecase
Description: This use case describes the process of making the loan
Pre-conditions: The user had to download and install this application;
The user has already done the “Signup” use case;
Post Conditions: The system handles and stores the data of the selections of
the user
The system stores the input from the user
the app
2 System performs credit Check
3 System displays the available Loan for the user based on credit;
4 User performs making Loan
5 User fill in the text boxes in the Loan form
6 System updates the time System and user repeat steps 3 to
5 until the user clicks the “back” button;
7 Finish;
Alternative Course: In step 4 of the Flow, the user can make different types of loan
packages:
1) Make the hot loan one time;
2) Make the unsecured loan one time;
3) Make the overdraft loan one time;
4) Make the instalment loan one time;
5) Make the mortgage loan one time;
The use case continues at step 4 of the flow Exception: Application is no longer approved for use(occurs at step 1);
Crashing;
Requirements: The appropriate of the system and user;
Table 2: MakeLoan usecase
Trang 9Use case Name View Profile
Description: This use case describes the activities of viewing the profile
Pre-conditions: The user had to download and install this application;
The user had signed up successfully;
Post Conditions: The system handles and stores the data of the selections of
1 Enter the index of the loan which the user wants to cancel;
2 Pay for money fine;
3 System store change;
The use case continues at step 2 of the Normal Course
Crashing;
Requirements: The appropriate of the system and user;
Table 3: View Profile usecase
Description: This use case describes the moment when the user clicks logout
this game
Pre-conditions: The user had to download and install this game;
The User had to Sign up in this app;
Post Conditions: The system handles the data of the selections of the user
2 System handles the selection of the user;
3 System performs signing out the data of this user;
4 Finish;
Alternative Course:
Trang 10Requirements: The appropriate of the system and user;
Table 4: Logout Usecase
2.2 Class Diagram
a) Diagram:
Figure 2: Class Diagram
Trang 11b) Break Down Class Diagram and Explain:
Loans Concrete Classes:
Explanation:
According to the scenario above, the “Geth1gh” application will provide 5 primary loan packages; So, these classes also have 5 concrete classes that are responded to 5 loan packages: Hot Loans Class, Mortgage Loans Class, Unsecured Loans Class, Overdraft Loans Class and Instalment Loans Class Although each one also has its own features, these 5 concrete classes still have some features in common Hence, there is a base class(“Loans” Class) which contains the properties in common of 5 loan packages There is a bidirectional association between Loans class and User class and the relationship is “make” and the multiplicity between the “User” and the “Item” is “1 and 0…* It demonstrates that one instances of “user” class could make some loans or not The public access modifier properties and methods of the “Loans” class include:
Properties:
Amount: defines the amount of this loan
Interest Rate: defines the interest rate of this loan
Required Income: The income that this loan requires the customer have
LoanTerm: Defines the term that the customer deals with this loan
Liability: Defines the total Liability of this loan
Figure 3: Loans Concrete Classes
Trang 12 User: The customer who makes this Loan
SetLiability method: get the double parameter from input and assign it to the Liability Property
SetInterestRate Method: get the double parameter from input and assign it to the interest rate Property
Because of ensuring the encapsulation, the constructor of this base class has the access modifier is
“protected”(just permit subclasses to manipulate) 5 Loan concrete classes now are the subclasses and they inherit the “Loans” base class to share the features in common There are distinct features of each Loan concrete class:
Hot Loan Class: two properties that are “requiredincome” and “InterestRate” are set to default(0 for
“requiredincome” and 27 for “InterestRate” ) once the instance of this class is initialized
Mortgage Loan Class: Two additional properties of this class are “Collateral”(Which defines the collateral which the customer wants to mortgage) and “Purpose”(It stores the purpose of the customer why they want to make a Mortgage Loan) The additional method of this class is “set requiredincome”(get the double parameter from input and assign it to the required income Property)
Unsecured Loan Class: this class is quite like the base class, the only different thing is the Interest rate of this Loan will set the default to 21 once its instance is initialized
Overdraft Loan Class: Because the Loan limit is based on the balance in the bank account of the customer, this class has a bank account property(defines the bank account of the customer) and the other additional property is Collateral(May or may not defines the collateral of the customer)
Instalment Loan Class: Because the Loan Limit and the prepayment property of this class will be set based on the instalment Item, this class has the additional item that is Item(which defines the instalment item of the customer) The distinct method of this Class is SetPrepayment(get the double parameter from input and assign it to the prepayment Property)
Client Concrete Class:
Figure 4: Client Concrete Class
Trang 13Explanation:
There are 3 classes which represent 3 primary objects that store the information of the customer including Item(defines the collateral as well as the instalment Item of the customer), Bank(defines the bank account of the customer) and User(the concrete class defines all basic information of the customer needs when making any loan anywhere)
The bidirectional association between the “User” class and “Item” class as well as between the “User” class and “Bank” class demonstrates that the relationship also is possing However, the multiplicity between the “User” and the “Item” is “1 and 0…*” which means each user’s instance when being initialized could have some Items(Item represent for instalment Items and Collateral; hence, it could appear to initialize more than one time) or not And the multiplicity between “User” and “Bank” is “1 and 0…1” which means each user’s instance when being initialized could have only one bank account
or not
For specific, there are the properties and methods of each class:
User Class:
Properties(Public access modifier with protected setter):
Name: Defines the full name of the customer
Age: Defines the age of the customer
Identity Card: The number sequence on the National Identity Card of the customer
Income: The monthly income of the customer
isHavingJob: Defines whether the Customer has a fixed job or not(fixed-job doesn’t include
“freelancer”)
BankAccount: Defines the bank account of the user
LoanStatus: Defines the status which is assessed in the customer’s loan history
Loanlists: The list of loans the customer makes
Bank Class:
Properties(Public access modifier with protected setter):
Name: The card name
CardNumber: The number on the bank card
ExpiredDate: The expired date wrote on the bank card
Balance: Defines the current balance of this bank card
Trang 14Item Class:
Properties(Public access modifier with protected setter);
Name: Defines the name of the Item
Value: The actual value of this Item(VND)
Document: Defines whether this Item has a full document or not
Loans Factory Method Design Pattern:
Explanation:
Based on factory design pattern logic, these Loan Factory Classes will substitute the calls to a unique factory method for direct object construction calls (initialize any loan in 5 primary concrete loan classes using the new operator) However, the new operator of Loan Concrete Class is still used to construct the objects, but it is now called from within the factory method(CreateLoan method) Loans now are frequently used to describe objects that a factory method returns
The ILoansFactory interface declares a method(CreateLoan) that is intended to return an instance of a Loans Class Loan Factory Concrete classes are able to indirectly change that logic by implementing the factory method and returning a different type of Loan from it These 5 Loan factory(responding to 5 primary loan packages) concrete classes implement the factory method(CreateLoan) so that changing the resulting Loan's type Although the method of Loan Factory concrete Class still uses the Loans as type, the Loan concrete class instance is actually returned from the method
Return a new loan is not the primary responsibility of the loan concrete class, it still has some logic related to Loan Hence, there are three classes which help loan factory concrete class perform logic when creating loan such as “PrepaymentImplement” class, “InterestRateImplement” class and
Figure 5: Loans Factory Method Design Pattern
Trang 15“Liability Calculator” class The bidirectional association between them and Loan Factory concrete classes demonstrates that they will be used by Loan Factory concrete classes
CreditChecker Classes
Explanation:
These classes and interface are represent for the checking credit of customers when they sign up Because the difference in each checking way and each type of checking is used for each type of loan, these checking types are extracted into separate classes called Fast Checker and Complex Checker The interface IcreditChecker declares the CreditCheck method which gets the User object as its parameter with the type of method is CreditType(enum) to all supported types of checker class Two classes(Fast Checker and ComplexChecker) implement this interface to set their all-handling logic for checking the credit of the user The CheckerService class contain the property as the reference to any type of checker, the CheckerService class will work with any type of checker via IcreditChecker Interface In other words, The IcreditChecker interface makes FactChecker and ComplexChecker classes interchangeable in the CheckerService Class The bidirectional association between CheckerService and User class will be demonstrated by AutomaticChecker
Enum
There are two primary enums which are StatusType(Good, Pure, Remarkable and
Bad) and CreditType(High, Medium, Low) The StatusType is frequently used to set
the LoanStatus of User and The CreditType is the resulting return of Checker class
when it performs checking on customer
Figure 6: Credit Checker Classes
Figure 7:Enum
Trang 16C IMPLEMENTATION
1 Code(Related to Class Diagram)
Because The Code which is related to Class Diagram above will be used many times in the program, all of
the codes below have been located in the Class Library, which is a library that contains classes, interfaces,
functions, etc… that can be used by more than one program at a time
1.1 Loan Concrete Class
Based on the class diagram above, the code of the Loan Concrete Class will be a total of 6 classes including one BaseClass and five SubClasses which inherit the BaseClass
a) BaseClass – “Loans” class:
Figure 8: Loans CLass
Explanation: The “loans” class has declared all the properties in common which the subclasses(5
Loan type concrete class) would inherit to use them These properties also have been introduced in the class diagram above All of these properties also have been set to public access modifier and protected setter with the data type presented in the image above To ensure that the client code cannot initialise any instance of Loans Class directly by using the new() operator, The access modifier
of the “Loans” constructor has been set to “Protected”(only inherited classes could inherit this constructor)
To follow the Single Responsibility principle, this class only has two methods and both of them also
be used to get the parameter and assign it to the properties in this class Method SetLiability which gets the double input as a parameter will set the Liability resulting after calculating by business logic
in other class to the Liability Property for the instance of Loans Method SetInterestRate also is like
Trang 17the SetLiability method, it also gets the double input as a parameter and takes this parameter assigning it to the interest rate Property
This class also has overridden the tostring() function to format the output for an object of this class CulcutureInfo is an available service used by adding the System.Globalization library of C#, which allows getting the VND format for the VND output of Liability and the Amount of Loan After all, return the string as output
b) SubClasses of “Loans” Class(HotLoan, UnsecuredLoans, OverdraftLoans, InstalmenLoans, MortgageLoans)
HotLoans Class
Explanation: This class inherits the Loans class to take the properties in common However,
instead of set Interest Rate by function, the InterestRate property of this one will be assign to
26 whenever the instance of Hotloans is initialized(It may look a bit illogical because client code also could call setInterestRate to set the interest rate of it Although this issues partly might be solved by using factory method it will hide concrete class, I also could optimize by setting the Loans class to abstract class and the SetInterestRate method would be abstract;
so, each class could implement it or do nothing with it)
The constructor of HotLoans takes three parameter: amount(double), user(User), loanTerm(double) and the properties also would be assigned based on the inputted parameter This one also override the ToString() method to return its own ouput
Figure 9: HotLoans Class
Trang 18 UnsecuredLoans Class
Explanation: UnsecuredLoans class inherits the Loans class to take the properties in
common However, instead of set Interest Rate by function, the InterestRate property of this one will be assign to 21 whenever the instance of UnsecuredLoans is initialized(It may look a bit illogical because client code also could call setInterestRate to set the interest rate of it Although this issue partly might be solved by using the factory method it will hide the concrete class, I also could optimize by setting the Loans class to abstract class and the SetInterestRate method would be abstract; so, each class could implement it or do nothing with it)
The RequiredIncome property also would be set to 4000 whenever the instance of UnsecuredLoan class is initialized
Like HotLoans, the constructor of UnsecuredLoans also takes three parameter: amount(double), user(User), loanTerm(double) and the properties also would be assigned based on the inputted parameter This one also overrides the ToString() method to return its own output
OverdraftLoans Class
Figure 10: Unsecured Loan Class
Trang 19Explanation: Above class inherits the Loans class to take the properties in common However, this class declares two new properties: Collateral(Item) defining the Collateral that user use it to make the Overdraft Loan package and BankAccount(Bank) which store the information for bank account of the user because of the feature of Overdraft(Overdraft Loan will decide the Loan limit based on the balance of user’s bank account) The RequiredIncome property also would be set to
5000 whenever the instance of the OverdraftLoan class is initialized
Because Overdraft Loan has two options which are making an Overdraft Loan without Collateral and without Collateral, The Interest and something else also change based on two options So, this class also applies overloading to have two constructors with a different number of parameters The first constructor of OverdraftLoans will take the option in which the user has collateral and it takes five parameters: amount(double), user(User), loanTerm(double), bank(Bank) and collateral(Item) and the properties also would be assigned based on the inputted parameter The other Constructor will take less than the first constructor one parameter and it is collateral(Item) because the second constructor will meet the option which doesn’t have collateral This one also overrides the ToString() method to return its own output
Figure 11: Overdraft Loan Class
Trang 20 InstalmenLoans Class
Explanation: This class inherits the Loans class to take the properties in common However,
this class declares two new properties: Item(Item) defining the instalment Item that user want to make the Instalment Loan package to help buy it and Prepayment(Bank) which store the amount that the user needs to pre-pay before the office disburse this loan to the user The RequiredIncome property also would be set to 6000 whenever the instance of the InstalmentLoan class is initialized
The constructor of InstalmentLoans will take four parameters: amount(double), user(User), loanTerm(double), and Item(Item) and the properties also would be assigned based on the inputted parameter
Specifically, unlike other concrete Loan Classes, this class declares the new method for only this one and it is the SetPrepayment method This method will get the double input as a paramenter and assign this parameter for the prepayment property of its object This one also overrides the ToString() method to return its own ouput
Figure 12: InstalmentLoan Class
Trang 21 MortgageLoans Class
Explanation: This class also inherit the Loans class to take the properties in common
Nevertheless, this class declares two new properties: Collateral(Item) defining the Collateral that user use it to make the Mortgage Loan package and Purpuse(string) which store the purpose why the user wants to make this mortgage Loan
Because Mortgage Loan always need a collateral, the constructor of MortgageLoans will take five parameters: amount(double), user(User), loanTerm(double), purpose(string) and collateral(Item) and the properties also would be assigned based on the inputted parameter Specifically, this class also declare the new method and it is the SetRequiredIncome method This method will get the double input as a paramenter and assign this parameter for the RequiredIncome property of its object This one also overrides the ToString() method to return its own ouput
Figure 13: MortgageLoan class
Trang 221.2 Client Concrete Classes
As I said in the class diagram, Client concrete classes are some classes created to store and define the information for the client-side They include User, Bank and Item classes
a) User Class
Figure 14: User Class
Explanation: Because this class was created to define and store the particular information of
the user, it and its objects are used, called and initialized widely and frequently in other classes such as 5 factory concrete classes, Credit Checker classes, calculator classes and also in GUI code
The properties of this User class have been introduced in the class diagram above This class has two constructors, the first constructor is called when the user enters their bank account as their information and the second one is called when the user signs up for this app without any bank account
For testing the ability of the Credit checker service, the LoanStatus of this Loan will be random whenever the instance of the user class is initialized This method will be random based on the length of StatusType
SetLoanStatus method will get the StatusType input as a parameter and assign this parameter for the LoanStatus property of its object, this function is used in the GUI logic when the user disposes of the loan suddenly or they violate the Loan principles