Download Unit 20: Applied Programming and Design Principles and more Essays (university) Cyberlaw and Internet 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 22 /07/2024 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyễn Minh Ánh Student ID BH Class SE06203 Assessor name Lương Thị Minh Huế 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 Anh Grading grid P1 P2 M1 P 3 P 4 M2 D
Summative Feedback: Resubmission Feedback:
Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date:
- I. INTRODUCTION:
- II. BODY:
- system(P1) Task 1: Discuss how good design principles could lead to good impacts for the quality of the
- OOP
- Class Relationships.........................................................................................................................
- SOLID Principles
- operations(P2) Task 2: Explain how clean coding techniques can impact on the use of data structures and
- Definition of clean code
- Impact on Data Structures and Operations
- Task 3: Design the application’s architecture and a suitable testing regime for SIMS(P3, P4)................
- Definition of UML
- Project diagrams
- Diagram 3. Integration with SOLID Principles, Clean Code Techniques, and Design Patterns in the Sequence
- Diagram 4. Integration with SOLID Principles, Clean Code Techniques, and Design Patterns in the Sequence
- SIMS Testing regime
- your team proposed solution(M1, M2) Task 4: Analyze how creational, structural and behavioral design patterns are used in pratices or in
- Definition of design patterns
- Creational patterns
- Structure patterns
- Behavior patterns
- Design patterns that are used in proposed solutions
- design and development.(D1) Task 5: Analyze the SIMS application and evaluate how adhering to SOLID principles has influenced the
- Analyze the SIMS application
- Analyze how adhering to SOLID principles has influenced the design and development in SIMS
- Evalute
- III. CONCLUSION:
- IV. EVALUATE:
- V. REFERENCES:
- Figure 1 OOP Table of Figure
- Figure 2 Example Code Encapsulation
- Figure 3 Example Code Inheritance and polymorphism
- Figure 4 Example Code Abstraction
- Figure 5 The main program
- Figure 6 SOLID
- Figure 7 Clean Code
- Figure 8 Code example Using meaningful name
- Figure 9 Code example writing comments...................................................................................................
- Figure 10 Code example Indentation and Formatting
- Figure 11 Code example follow TDD principle
- Figure 12 Code example follow SOLID principle
- Figure 13 Code example follow DRY principle
- Figure 14 Code example using correct encapsulation
- Figure 15 ULM
- Figure 16 Test Regime
- Figure 17 Automated Testing
- Figure 18 Manual Testing
- Figure 19 Unit Test
- Figure 20 Integration Test
- Figure 21 End-to-End Test
- Figure 22 Test-Driven Development (TDD)
- Figure 23 Continuous Integration (CI)
- Figure 24 Example Unit Test
- Figure 25 Design Pattern
I. INTRODUCTION: In the context of an increasing number of student information management systems (SIMS) being developed to meet the complex and diverse data management needs of educational organizations, designing and building an effective SIMS system is very important. My role in this project was as lead developer, responsible for the design, implementation, and quality assurance of the system. Requirements include building a secure, easy-to-use and scalable system, with key functions such as managing student, lecturer, and course information, along with ensuring security and user authorization. In the process of building this SIMS system, I will apply a variety of professional knowledge, including object-oriented programming (OOP), writing and executing test cases, and SOLID principles. Object- oriented programming will help me design objects and their relationships in a logical and effective way. Test cases will ensure that the system functions as expected. SOLID principles will make the system's source code easier to maintain, extend, and minimize errors. These concepts are not only important in building systems but also provide a solid knowledge base for developing other software projects in the future. One of the outstanding advantages of this system is the user authentication and authorization mechanism (User Authentication and Authorization). The system will ensure secure user authentication for students, lecturers, and administrators. At the same time, applying role-based authorization limits system functions based on user roles, ensuring that only administrators can perform sensitive tasks such as adding, editing or delete information. This helps avoid students or faculty accessing administrator- only functions, thereby strengthening the security of the system. By using a strict authentication mechanism, users will avoid unauthorized access, helping to strengthen system security. However, this system also has disadvantages that need to be considered. Some functions may be unclear in their implementation or may confuse the user. For example, there may be confusion about how to implement some complex permissions functionality or about how to ensure that all use cases are optimally secure. Additionally, during the process of building the system, I also encountered some personal weaknesses, such as lack of experience in specific technologies or difficulties in ensuring all security requirements were met. executed properly. To support the stated pros and cons, I will use relevant research and reference sources. For example, documentation on object-oriented programming and SOLID principles will help demonstrate the correctness and benefits of these principles in programming. Research on information security will illustrate the importance of user and data security. Thereby, this information will help strengthen arguments about the advantages and disadvantages of the system, and provide specific solutions to overcome the mentioned disadvantages.
II. BODY: Task 1: Discuss how good design principles could lead to good impacts for the quality of the system(P1)
- OOP a) Definition of OOP OOP is the abbreviation for Object-oriented programming - object-oriented programming. This is a programming paradigm developed based on the concept of object technology. In particular, the object contains data, in fields often called attributes. Source code is organized into methods that help objects access and edit data fields of other objects with which the current object interacts. Simply put, object-oriented programming supports OOP technology. Has the effect of increasing productivity and speeding up work progress. From there, it allows programmers to influence subjects as in reality. Thereby, we can fix software errors and proactively maintain and maintain the system. Object- oriented programming languages are very diverse, most of them are class-based programming languages. Each object has the ability to receive messages, process data, and send responses to other objects or the environment. Figure 1 OOP b) Characteristics of OOP The four main characteristics of OOP are Encapsulation, Inheritance, Polymorphism, and Abstraction. Each of these characteristics helps to create modular, reusable, and maintainable code. Below, we will explore each characteristic in detail, along with C# code examples to illustrate their implementation: o Encapsulation
➢ Description: Encapsulation is the practice of wrapping data and the methods that operate on the data within a single unit, known as an object. The object's attributes are usually kept private and can only be accessed through public methods. ➢ Purpose: Protects data from unauthorized access or modification. It increases data security and integrity. ➢ Example Code: This class demonstrates encapsulation in object-oriented programming. Figure 2 Example Code Encapsulation
- The Person class has two private attributes: name and age.
- These attributes are encapsulated, meaning they are private and cannot be accessed directly from outside the class.
- Public methods GetName, SetName, GetAge, and SetAge are provided to access and modify these private attributes. o Inheritance ➢ Description: Inheritance allows the creation of a new class based on an existing class. The subclass inherits the attributes and methods of the superclass and can extend or override them. ➢ Purpose: Promotes code reuse, reduces redundancy, and enhances flexibility in software design. ➢ Example Code: This class demonstrates inheritance and polymorphism.
Figure 4 Example Code Abstraction
- The Student class is abstract and contains an abstract method DisplayStudentDetails, which means it does not have an implementation and must be implemented by derived classes.
- UndergraduateStudent is a derived class that provides an implementation for the DisplayStudentDetails method.
- This demonstrates abstraction, where the Student class provides a blueprint that derived classes must follow. And finally , Program.cs - This is the main program that demonstrates how these classes work together. Figure 5 The main program Encapsulation Example:
- A Person object is created.
- The SetName and SetAge methods are used to set the name and age of the person.
- The GetName and GetAge methods are used to print the name and age to the console. Inheritance Example:
- A MathCourse object is created.
- The CourseDetails method of the MathCourse class is called, which prints "Math course details". Polymorphism Example:
- An array of Course objects is created, containing both MathCourse and ScienceCourse objects.
- The CourseDetails method is called for each object in the array, demonstrating how the method behaves differently depending on the object type. Abstraction Example:
- An UndergraduateStudent object is created with the name "MinhAnh" and the student ID "BH00644".
- The DisplayStudentDetails method is called, which prints the student's name and ID to the console.
- Class Relationships a) Definition of class relationship In object-oriented programming (OOP), class relationships define how classes are connected or associated with each other. These relationships help in modeling the real-world scenarios effectively and facilitate communication between different parts of a software system. b) Type of class relationships Association:
- Meaning: Association represents a relationship where one class knows about another class. It can be a simple link between objects with a "has-a" relationship, indicating that one class uses the services of another class.
- Example: In a school management system, a Teacher class and a Student class are associated. Each student is associated with one or more teachers who teach them different subjects. Aggregation:
- Meaning: Aggregation is a specialized form of association where one class (the whole) contains references to objects of another class (the part). It implies a "has-a" relationship, but the part can exist independently of the whole.
- Meaning: The OCP suggests that software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. This principle encourages developers to use abstraction (like interfaces or abstract classes) to allow new functionality to be added without altering existing code.
- Example: An Employee class can be extended to include new types of employees (e.g., Manager or Intern) by implementing the Employee interface or inheriting from the Employee base class. This ensures that existing employee-related code remains unchanged. c) Liskov Substitution Principle (LSP)
- Meaning: The LSP states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. In other words, subclasses should be able to substitute their base class without causing errors or unexpected behavior.
- Example: If a Square class inherits from a Shape class, it should be able to replace any instance where a Shape is expected. This ensures that any method expecting a Shape object can handle a Square object without issues. d) Interface Segregation Principle (ISP)
- Meaning: The ISP emphasizes that clients should not be forced to depend on interfaces they do not use. Instead of one large interface, it is better to have smaller and more specific interfaces that clients can implement selectively.
- Example: If an Accountant class only needs methods for CalculateTax and GenerateReport, it should implement an IAccountant interface with just these methods. This avoids unnecessary dependencies on methods like MakeCoffee that the Accountant class doesn't need. e) Dependency Iversion Principle (DIP) Meaning: The DIP suggests that high-level modules should not depend on low-level modules. Both should depend on abstractions (like interfaces or abstract classes). It also advocates that abstractions should not depend on details, but details should depend on abstractions. Example: Instead of directly depending on specific database classes, a DataAccessLayer class should depend on an IDataAccess interface. This allows different database implementations (MySQL, PostgreSQL, etc.) to be easily swapped without affecting other parts of the system. Task 2: Explain how clean coding techniques can impact on the use of data structures and operations(P2)
- Definition of clean code Clean code is a concept in software development that emphasizes writing code that is easy to read, understand, and maintain. The goal of clean code is to produce software that is not only functional but
also clear and well-organized, making it easier for developers to work with over time. Here are the key principles of clean code:
- Readability: Clean code is designed to be easily readable by anyone who may work on it, including your future self. This involves using meaningful names for variables, functions, and classes, and structuring the code in a way that logically follows the problem domain. Readable code reduces the cognitive load required to understand what the code does and why.
- Maintainability: The code is structured to be easily modifiable and extendable. This means that it should be straightforward to add new features, fix bugs, or refactor without breaking existing functionality. Good maintainability ensures that the codebase can evolve and adapt to new requirements over time.
- Simplicity: Clean code adheres to the principle of simplicity, meaning it avoids unnecessary complexity and focuses on doing just what is needed. Simplicity helps in reducing the number of bugs and makes the code easier to test and debug.
- Consistency: Consistent code follows a set of conventions and styles throughout the codebase. This consistency makes it easier for developers to understand and work with the code, as they don't have to deal with varying coding styles and practices.
- Modularity: The code is organized into well-defined, reusable modules or functions. Each module or function has a clear responsibility and is designed to be as independent as possible. This modularity enhances the code’s structure and makes it easier to test and debug.
- Self-documenting: Good code often explains itself through its structure and naming conventions, reducing the need for excessive comments. However, comments are still used to explain why certain decisions were made or to provide additional context that is not immediately obvious from the code itself. In essence, clean code is about writing code that is not only functional but also clear, well-organized, and easy to maintain. It involves applying best practices in programming to ensure that the codebase remains manageable and adaptable throughout its lifecycle.
- Descriptive Names: The class Student and members ‘StudentId’, ‘StudentName’, and ‘EnrollInCourse’ clearly describe their purpose and make the code easier to understand. b) Writing comments Definition: Comments provide explanations or context for complex or non-obvious code segments, making it easier for others to understand what the code is doing. Good comments explain why the code is doing something, not just what it is doing. Code Example: Figure 9 Code example writing comments Explanation:
- Comments: The comments above each method explain their purpose, making the code more understandable. Anyone reading the code can quickly grasp that ConvertCelsiusToFahrenheit converts temperatures from Celsius to Fahrenheit, and ConvertFahrenheitToCelsius does the reverse. c) Indentation and Formatting Definition: Proper indentation and consistent formatting enhance code readability and maintainability. Well- formatted code makes it easier to understand the structure and flow, reducing the likelihood of errors. Code Example:
Figure 10 Code example Indentation and Formatting Explanation:
- Proper indentation and formatting make the code more readable and maintainable. d) Follow TDD principle Definition: Magic numbers are hard-coded values in the code that lack context. Using named constants makes the code more readable and easier to understand. Code Example: Figure 11 Code example follow TDD principle Explanation:
f) Follow DRY principle Definition: The Don't Repeat Yourself (DRY) principle emphasizes reducing repetition by abstracting repeated logic into reusable methods. This makes the code easier to maintain and reduces the risk of inconsistencies. Code Example: Figure 13 Code example follow DRY principle Explanation:
- Repetitive Code: The validation logic is repeated in both ‘SaveUser’ and ‘UpdateUser’.
- DRY Code: The validation logic is extracted into a separate ‘ValidateUser’ method, reducing repetition and making the code easier to maintain. g) Using correct encapsulation Definition:
Encapsulation restricts direct access to some of an object's components, which helps protect the integrity of the data. It is achieved by making fields private and providing public methods to access and modify the data. Code Example: Figure 14 Code example using correct encapsulation Explanation:
- Encapsulation: The balance field is private, preventing direct modification from outside the class. The Deposit and Withdraw methods control how the balance is modified, ensuring that it can only be changed in valid ways. By following these clean code techniques, you can significantly improve the readability, maintainability, and scalability of your code. Each technique ensures that the code is well-structured and easy to work with, leading to better overall software quality.