Docsity

Clean Code and Test Automation in Software Development, Thesis of Commercial Law

Toggle sidebar
bg1
ASSIGNMENT 1 FRONT SHEET
Qualification Pearson BTEC Level 5 Higher National Diploma in Computing
Unit number and title Unit 20: Applied Programming and Design Principles
Submission date Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Nguyen Trong Phong Student ID BH01180
Class SE06.206 Assessor name Dao Tran Chung
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 P3 P4 M2 D1
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

Partial preview of the text

Download Clean Code and Test Automation in Software Development and more Thesis Commercial Law in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification Pearson BTEC Level 5 Higher National Diploma in Computing Unit number and title Unit 20: Applied Programming and Design Principles Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyen Trong Phong Student ID BH Class SE06.206 Assessor name Dao Tran Chung 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 P3 P4 M2 D

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date:

  • I. Introduction........................................................................................................................................................
  • II. Contents..............................................................................................................................................................
    • principles................................................................................................................................................................. 1. Investigate the characteristics of the object- orientated paradigm, including class relationships and SOLID
      • a. Introduction to Oject-Oriented Paradigm (OOP)........................................................................................
      • b. Class Relationships.....................................................................................................................................
      • c. SOLID Principles..........................................................................................................................................
    • writing algorithms.................................................................................................................................................. 2. Explain how clean coding techniques can impact on the use of data structures and operations when
    • design pattern........................................................................................................................................................ 3. Design a large data set processing application, utilizing SOLID principles, clean coding techniques and a
      • a. Use case diagram......................................................................................................................................
      • b. A Class Diagram........................................................................................................................................
      • c. A package diagram...................................................................................................................................
      • d. An explanation of how SOLID principles have been applied in your team design....................................
      1. Design a suitable testing regime for the application, including provision for automated testing.................
      • a. Test Automation.......................................................................................................................................
      • b. Why Automate Testing?...........................................................................................................................
      • c. How to Automate Testing.........................................................................................................................
      • d. Types of Automate Testing.......................................................................................................................
      • e. Test Automation Tools.............................................................................................................................
  • III. Conclusion....................................................................................................................................................
  • IV. References....................................................................................................................................................
  • Figure 1: OOP...............................................................................................................................................................
  • Figure 2: Class Relationship.........................................................................................................................................
  • Figure 3: Aggregation..................................................................................................................................................
  • Figure 4: SOLID............................................................................................................................................................
  • Figure 5: Single Responsibility Princle........................................................................................................................
  • Figure 6: Open/Closed Principle................................................................................................................................
  • Figure 7: Liskov’s Substitution Principle.....................................................................................................................
  • Figure 8: Interface Segregation Principle...................................................................................................................
  • Figure 9: Dependency Inversion Principle.................................................................................................................
  • Figure 10: Use Case Diagram.....................................................................................................................................
  • Figure 11: A Class Diagram........................................................................................................................................
  • Figure 12: A Package Management...........................................................................................................................
  • Figure 13: Testing Pyramid........................................................................................................................................
  • Figure 14: Types of Automate Testing.......................................................................................................................

I. Introduction

In the realm of software development, the effectiveness of an application is significantly influenced by its design, implementation, and maintenance. This ASM aims to provide a thorough exploration of foundational concepts and best practices essential for robust and efficient software engineering. We begin with an examination of the Object-Oriented Paradigm, delving into its core principles and the relationships between classes. This paradigm has become a cornerstone in software development due to its ability to model real-world entities and interactions in a modular and reusable manner. Next, we investigate the impact of clean coding techniques on the utilization of data structures and operations. Clean code is crucial for maintaining readability, reducing complexity, and ensuring that software can be efficiently modified and extended. We discuss principles such as meaningful naming, modularity, and consistency, highlighting their influence on algorithm design and data management. Following this, we present the design of a large data set processing application, emphasizing the application of SOLID principles and clean coding techniques. The use of design patterns, which offer proven solutions to common problems, is also highlighted. Detailed diagrams, including use case, class, and package diagrams, illustrate the proposed architecture of the application.

  • Abstraction. Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. The derived class can have its functionality extended. This concept can help developers more easily make additional changes or additions over time.
  • Inheritance. Classes can reuse code and properties from other classes. Relationships and subclasses between objects can be assigned, enabling developers to reuse common logic, while still maintaining a unique hierarchy. Inheritance forces more thorough data analysis reduces development time and ensures a higher level of accuracy.
  • Polymorphism. Objects are designed to share behaviors, and they can take on more than one form. The program determines which meaning or usage is necessary for each execution of that object from a parent class, reducing the need to duplicate code. A child class is then created, which extends the functionality of the parent class. Polymorphism enables different types of objects to pass through the same interface. (BasuMallick, 2022)

b. Class Relationships

Understanding the relationships between classes is essential for designing a robust system. Here we define association, aggregation, and composition, and provide real-world examples for each relationship.

 Association

The objects that are part of the association relationship can be created and destroyed independently.

  • Association is a semantically weak relationship (a semantic dependency) between otherwise unrelated objects.
  • An association is a “using” relationship between two or more objects in which the objects have their own lifetime and there is no owner.
  • Composition and Aggregation are the two forms of association. Figure 2 : Class Relationship

Example: An association relationship between two classes is a “has a” relationship. For example:  A Car has an Engine and a Wheel  A Person has a Leg and an Arm  A Book has Pages  A doctor has many patients and patient can consult many doctors (Each of these objects has its own life cycle and there is no “owner” or parent) ie.  ClassA contains ClassB as an attribute, or  Instances of ClassB are constructed inside ClassA

 Aggregation

  • Aggregation is a specialized form of association between two or more objects in which each object has its own life cycle but there exists ownership as well.
  • An essential property of an aggregation relationship is that the whole or parent (i.e. the owner) can exist without the part or child and vice versa.
  • The life cycles of parent objects and child objects are independent. In a composition relationship, the death of a parent object also means the death of its children.
  • examplA department can have students but vice versa is not possible and thus unidirectional in nature.
  • In Aggregation, both the entries can survive individually which means ending one entity will not affect the other entity. Figure 3 : Aggregation

 Composition

Figure 5 : Single Responsibility Princle This principle states that “A class should have only one reason to change” which means every class should have a single responsibility or single job or single purpose. In other words, a class should have only one job or purpose within the software system. Let’s understand Single Responsibility Principle using an example: Imagine a baker who is responsible for baking bread. The baker’s role is to focus on the task of baking bread, ensuring that the bread is of high quality, properly baked, and meets the bakery’s standards.

  • However, if the baker is also responsible for managing the inventory, ordering supplies, serving customers, and cleaning the bakery, this would violate the SRP.
  • Each of these tasks represents a separate responsibility, and by combining them, the baker’s focus and effectiveness in baking bread could be compromised.
  • To adhere to the SRP, the bakery could assign different roles to different individuals or teams. For example, there could be a separate person or team responsible for managing the inventory, another for ordering supplies, another for serving customers, and another for cleaning the bakery.

Open/Closed Principle

Figure 6 : Open/Closed Principle This principle states that “Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification” which means you should be able to extend a class behavior, without modifying it. Let’s understand Open/Closed Principle using an example: Imagine you have a class called PaymentProcessor that processes payments for an online store. Initially, the PaymentProcessor class only supports processing payments using credit cards. However, you want to extend its functionality to also support processing payments using PayPal. Instead of modifying the existing PaymentProcessor class to add PayPal support, you can create a new class called PayPalPaymentProcessor that extends the PaymentProcessor class. This way, the PaymentProcessor class remains closed for modification but open for extension, adhering to the Open-Closed Principle

Interface Segregation Principle

Figure 8 : Interface Segregation Principle This principle is the first principle that applies to Interfaces instead of classes in SOLID and it is like the single responsibility principle. It states that “do not force any client to implement an interface which is irrelevant to them “. Here your main goal is to focus on avoiding fat interface and give preference to many small client-specific interfaces. You should prefer many client interfaces rather than one general interface and each interface should have a specific responsibility. Let’s understand Interface Segregation Principle using an example: Suppose you enter a restaurant, and you are pure vegetarian. The waiter in that restaurant gave you the menu card which includes vegetarian items, non-vegetarian items, drinks, and sweets.  In this case, as a customer, you should have a menu card which includes only vegetarian items, not everything which you don’t eat in your food. Here the menu should be different for different types of customers.  The common or general menu card for everyone can be divided into multiple cards instead of just one. Using this principle helps in reducing the side effects and frequency of required changes.

Dependency Inversion Principle

Figure 9 : Dependency Inversion Principle The Dependency Inversion Principle (DIP) is a principle in object-oriented design that states that “High- level modules should not depend on low-level modules. Both should depend on abstractions “. Additionally, abstractions should not depend on details. Details should depend on abstractions.  In simpler terms, the DIP suggests that classes should rely on abstractions (e.g., interfaces or abstract classes) rather than concrete implementations.  This allows for more flexible and decoupled code, making it easier to change implementations without affecting other parts of the codebase. Let’s understand Dependency Inversion Principle using an example: In a software development team, developers depend on an abstract version control system (e.g., Git) to manage and track changes to the codebase. They don’t depend on specific details of how Git works internally. This allows developers to focus on writing code without needing to understand the intricacies of version control implementation.

Example:

 Bad Practice: Naming a function that adds a student to the list as a.

public void a(string name, int grade) { students.Add(new Student(name, grade)); }  Good Practice : Naming the function as AddStudent. public void AddStudent(string name, int grade) { students.Add(new Student(name, grade)); }  Bad Practice : Naming a function that calculates the average grade as ag. public double ag() { int total = 0; foreach (var student in students) { total += student.Grade; } return total / (double)students.Count; }

Good Practice : Naming the function as CalculateAverageGrade. public double CalculateAverageGrade() { int totalGrade = 0; foreach (var student in students) { totalGrade += student.Grade; } return totalGrade / (double)students.Count; } In these examples, the function names AddStudent and CalculateAverageGrade make it clear what each function does. This clarity helps developers quickly understand the code, reduces the chance of misuse, and facilitates easier maintenance and debugging. Meaningful naming significantly enhances code readability and understanding by providing clear, descriptive names for data structures and operations. This practice is crucial for writing clean, maintainable, and self-explanatory code, which is especially beneficial for new programmers.

In this example, the Student class is focused on the properties and behavior of a student, the StudentRepository class is responsible for managing the collection of students, and the StudentService class is responsible for business logic operations like calculating the average grade and printing student details.