PROGRAM TITLE Applied Programming UNIT TITLE1
PROGRAM TITLE Applied Programming UNIT TITLE1
Internal verification:
Contents
Table of Contents
I. Investigate the impact of SOLID development principles on the OOP paradigm................................ 4
1. Investigate the characteristics of the object-orientated paradigm, including class relationships
and SOLID principles..................................................................................................................... 4
1.1.Presentation of object-oriented programming? Why object-oriented programming is widely
applied in large, complex software..................................................................................................... 4
1.2.Presentation of class and subject........................................................................................................ 4
1.3.2. Inheritance........................................................................................................................... 5
1.3.3 Polymorphism................................................................................................................................. 5
1.3.4. Abstraction..................................................................................................................................... 5
1.4.State relationships between classes: inheritance, association, aggregation........................................ 5
1.4.2. Affiliation (association)....................................................................................................... 6
1.4.3. Kết tập (aggregation/composition)...................................................................................... 6
1.5.Present the Solid principle: state the principles.................................................................................. 6
1.5.1. Single Responsibility Principle (SRP)................................................................................ 6
1.5.2. Open/Closed Principle (OCP)............................................................................................. 6
1.5.3. Nguyên tắc thay thế Liskov (Liskov Substitution Principle - LSP).................................... 6
1.5.4. Interface Segregation Principle (ISP).................................................................................. 6
1.5.5. Dependency Inversion Principle (DIP)............................................................................... 7
2. Explain how clean coding techniques can impact on the use of data structures and operations when
writing algorithms.............................................................................................................................. 7
2.2.Give ways to apply clean cod............................................................................................................. 7
2.3.Clean code is also applied in selecting appropriate data structures. When building an app that must
perform frequent searches, why use................................................................................................... 8
3. Analyse, with examples, each of the creational, structural and behavioural design pattern types.....9
3.2.Name the design pattern groups and design patterns in each group.................................................. 9
3.3.In each design pattern group, let's take a specific example that includes the diagram class and
implementation code........................................................................................................................ 10
Class Diagram.................................................................................................................................. 10
• Class Diagram.................................................................................................................................. 13
II. Design a large dataset processing application using SOLID principles and clean coding techniques.
16
1. Design a large data set processing application, utilising SOLID principles, clean coding techniques
and a design pattern.......................................................................................................................... 16
2. Design a suitable testing regime for the application, including provision for automated testing....16
2.1.What is the presentation of testing? Why testing?........................................................................... 16
2.2.Presentation of unit testing, integration testing, system testing, user testing?................................. 16
III. Build a data processing application based ona developed design.................................................... 18
3.1. Build a large dataset processing application based on the design produced...................18
FILE MODEL........................................................................................................................................ 22
Application.java..................................................................................................................................... 26
3.2. Assess the effectiveness of using SOLID principles, clean coding techniques and
programming patterns on the application developed................................................................... 27
I. Perform automatic testing on a data processing application............................................................ 27
4.1. Examine the different methods of implementing automatic testing as designed in the test
plan. 27
BDD (Behavior-Driven Development):................................................................................................. 28
4.2. Implement automatic testing of the developed application............................................... 29
4.3. Discuss the differences between developer- produced and vendor- provided automatic
testing tools for applications and software systems..................................................................... 30
Vendor-Provided Automatic Testing Tools:.......................................................................................... 31
4.4. Analyse the benefits and drawbacks of different forms of automatic testing of
applications and software systems, with examples from the developed application...................31
Unit Testing:........................................................................................................................................... 31
Integration Testing:................................................................................................................................ 31
System Testing:...................................................................................................................................... 31
Performance Testing:............................................................................................................................. 31
Regression Testing:................................................................................................................................ 33
RENFERENCE...................................................................................................................................... 33
I. Investigate the impact of SOLID development principles on the OOP paradigm
1. Investigate the characteristics of the object-orientated paradigm, including class relationships
1.1. Presentation of object-oriented programming? Why object-oriented programming
is widely applied in large, complex software
Class and object are two basic concepts in object-oriented programming. A class is a template
that defines properties and methods for creating corresponding objects. An object is a specific
instance of a class with properties and methods defined in the class. The use of classes and
objects makes the source code easy to read and reuse, while minimizing dependencies between
program components.
For example, in a student management program, you can create a "Student" class and a "Course"
class to manage student information and corresponding courses. We can create objects from these
classes and link them to manage information about students and courses.
1.3.1. Encapsulation
Encapsulation is a property that allows to hide the information and behavior of an object from the
outside. It protects the properties and methods of an object from direct external access, and
allows access only through public methods. Packaging makes program components independent
and protects them from unexpected external change.
1.3.2. Inheritance
Inheritance allows a class to be created based on an already existing class. The new class (child)
will inherit the properties and methods of the old class (parent) and can add new properties and
methods or override existing methods. Inheritance makes the program easy to read, maintain, and
minimizes repetition of source code.
1.3.3 Polymorphism
Polymorphism is the property that allows a method to take many different morphologies,
depending on the object called. Objects created from different classes can have the same method
name but have different implementations. Polymorphism makes the program flexible and
scalable.
1.3.4. Abstraction
Abstraction is a property that allows concealing the details of an object's settings and focusing
only on important properties and methods. It allows the creation of abstract or interface classes to
define important methods and properties for the corresponding objects, without regard to specific
settings. Abstraction makes the program easy to read, maintain, and extensible, and helps to
isolate the components of the program for independent development.
1.4.1. Inheritance
Inheritance is the relationship between a parent class and a child class, where the child class is
created based on the parent class and inherits the properties and methods of the parent class.
Inheritance helps create inherited subclasses and extends the properties and methods of the parent
class.
1.4.2. Affiliation (association)
A bond is a relationship between two layers, where each layer has access to the components of
the other. Linking helps create complex objects by combining simpler objects. Linked objects can
be objects of the same class or objects of different classes.
2. Explain how clean coding techniques can impact on the use of data structures and
operations when writing algorithms.
+ Easy to expand
+ Increased security
+ Increase reusability
+ Minimize errors
+ Increase efficiency
1. Clearly name variables and functions: Clearly naming and accurately describing the function
of variables and functions makes the code easier to read and understand.
2. Keep the jaw short: The jaw should be kept short, not too long, and have only one
responsibility. Keeping functions short helps separate the different features in a function and
helps create independent and easy-to-maintain functions.
3. Use comments appropriately: Comments should be used to explain confusing code or special
functions of functions. However, comments should not be used to explain unreadable code or
to keep old code from being modified.
4. Use arguments and return values for their intended purpose: Function arguments and return
values should be used for their intended purpose. The purpose-driven use of arguments and
return values helps create independent functions that are easy to maintain.
5. Separate different features in a class: A class should have only one responsibility, i.e. it should
have only one reason to change. Separating different features within a class helps create classes
that are independent and easy to maintain.
6. Apply the SOLID principle: Apply the SOLID principles, including the Single Responsibility
Principle (SRP), Open/Closed Principle (OCP), Liskov Substitution Principle (LSP), Interface
Segregation Principle (ISP), and Dependency Inversion Principle (DIP) to create standalone
and easy-to-maintain modules in the application.
7. Use design patterns: Use design patterns to solve common programming problems and
create independent and easy-to-maintain modules and functions.
Use clean code tools: Use clean code tools such as SonarQube, PMD, Checkstyle, and
ReSharper to help test and improve the quality of your code.
8. Check and repair code regularly: Code should be tested and repaired regularly to minimize
the occurrence of bugs and increase the security and reliability of the application.
9. Code review: Codereview is the process of reviewing and evaluating other people's code to
find and fix bugs, improve the quality of code, and apply clean code principles in software
development. Code reviews help increase the quality of code, minimize errors and create higher
quality software products.
2.3. Clean code is also applied in selecting appropriate data structures. When building
an app that must perform frequent searches, why use
BinarySearch hơn Linear Search.
Clean code involves not only writing code that is easy to read and understand, but also includes
the use of appropriate data structures to optimize application performance.
In the case of searching for elements in an organized array, binary search is a more optimal
solution than linear search. The reason for this is that binary search can reduce the search time to
just O(log n), while Linear Search has an O(n) search time.
When using Linear Search, the order of the elements in the array does not matter. However, when
using Binary Search, the array must be sorted in advance. Otherwise, the use of Binary Search
will be ineffective and may lead to false results.
1. Creational Pattern: Object creation templates that make the creation of objects in the
application managed and optimized.
2. Structural Patterns: Structural patterns make organizing objects in the application easier and
more efficient.
3. Behavioral Patterns: Behavioral patterns make managing the activities of objects in the
application easier and more flexible.
Each design pattern will have different characteristics and uses, however, they are all created to
solve a specific problem in software design. The use of design patterns can make software
development easier, increase code uniformity and reusability, reduce code complexity, and
increase system maintainability.
3.2. Name the design pattern groups and design patterns in each group
Design patterns are an important concept in the field of software development, they are built to
solve repetitive problems during software development. The design pattern groups and design
patterns within each group include:
1. Creational Patterns: The design patterns in this group are used to create objects in the software.
- Abstract Factory Pattern
2. Structural Patterns: The design patterns in this group relate to the structure of objects and the
relationships between them.
- Adapter Pattern (Mẫu Adapter)
3. Behavioral Patterns: The design patterns in this group focus on how subjects interact with each
other and divide work.
3.3. In each design pattern group, let's take a specific example that includes the
diagram class and implementation code.
3.3.1. Creational Design Pattern - Factory Method Pattern
Class Diagram
Code Implementation:
Main.java
Circle.java
public class Circle implements Shape {
@Override
public void draw() {
System.out.println("Inside Circle::draw() method.");
}
}
Rectangle.java
Shape.java
ShapeFactory.java
Code Implementation:
Image.java
BaseImage.java
// Add Border
image = new Border(image);
image.display();
// Adjust Brightness
image = new Brightness(image);
image.display();
Result:
kjj
II. Design a large dataset processing application using SOLID principles and clean coding
techniques.
1. Design a large data set processing application, utilising SOLID principles, clean
coding techniques and a design pattern.
2. Design a suitable testing regime for the application, including provision for automated
testing
Testing is considered an important part of the software development process as it helps to ensure
that the product works as expected and meets the requirements of the customer. If the product is
not adequately tested, it may experience issues such as software bugs, poor performance, weak
security, or failure to meet customer requirements.
In addition, testing helps to minimize risks and costs during product development. By checking
and detecting defects early, developers can fix them before the product is released, minimizing
the cost of repairs and increasing product stability.
2.2. Presentation of unit testing, integration testing, system testing, user testing?
Unit Testing Integration Testing System Testing User testing
Unit testing is the process Integration testing is the System testing is the User testing is the
of checking the correctness process of checking the process of checking the process of checking
of smaller software correctness of software correctness of the entire the correctness of
components, called units. put together, called software system, software from the
The goal of unit testing is integration. The goal of including software, perspective of the
to determine if the units are integration testing is to hardware, and other end user. The goal
functioning as designed, determine if the software components. The goal of of user testing is to
meet requirements and are has been properly system testing is to determine if the
error-free. Unit testing is integrated, interacted determine if the system software meets the
usually done by with each other properly, is functioning as user's needs, making
programmers and works properly as designed and meets user it easy
Programmer and use of designed requirements Usage and properties
techniques scheme. Integration not. Test Us
Testing
techniques such as path It is usually done by test Systems are usually availability does not.
inspection, boundary value engineers and uses implemented by test User testing is
inspection and limit techniques such as UI engineers and use usually done by
condition checking to testing, communication techniques such as UX/UI professionals
ensure the accuracy and mechanism testing, and performance testing, and uses techniques
reliability of the units. storage mechanism security testing and such as user
testing to ensure system stability testing to ensure experience testing,
operability. the accuracy and interoperability
reliability of the system. testing, and usability
testing to ensure
reasonableness and
responsiveness of
user requirements.
SumTest.java
import org.junit.Test;
import static org.junit.Assert.*;
@Test
public void testSum() {
Sum s = new Sum();
int[] numbers = {1, 2, 3, 4, 5};
assertEquals(15, s.sum(numbers));
}
}
In this test suite, we create a new Sum object and an integer array with values
between 1 and 5. We then call the sum() method of the Sum object and use the
assertEquals() method to compare the result returned with the expected value of
15.
If the sum() method works correctly, the test suite will run successfully and
return a "PASSED" result. If any error occurs, for example the method returns an
incorrect result, the test method will report an error and return a "FAILED"
result.
TypeBookShopData.java
package data;
import Model.Book;
import java.util.List;
CSVBookData.java
package data;
import Model.Book;
import Model.BookTmpl;
import com.opencsv.CSVReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
@Override
public List<Book> getAllTitles() {
List<Book> bookList = new ArrayList<>();
tmpl.setPublicationYear((int)Float.parseFloat(row[COL_YEAR]));
} else {
tmpl.setPublicationYear(0);
}
bookList.add(tmpl);
}
} catch (Exception e) {
e.printStackTrace();
}
return bookList;
}
}
APIBookData.java
package data;
import Model.Book;
import java.util.List;
public APIBookData(){
throw new RuntimeException("API not yet supported");
}
@Override
public List<Book> getAllTitles() {
return null;
}
MySqlBookData
package data;
import Model.Book;
import java.util.List;
FactoryBookShopData.java
package data;
BookShop.interface
package Model;
int getPublicationYear();
String getLanguage();
BookShoplmpl.java
package Model;
@Override
public String getTitle() {
return null;
}
@Override
public String getAuthors() {
return null;
}
@Override
public double getRating() {
return 0;
}
@Override
public int getRatingsCount() {
return 0;
}
@Override
public int getPublicationYear() {
return 0;
}
@Override
public String getLanguage() {
return null;
}
@Override
public int getBooksCount() {
return 0;
}
@Override
public String toString() {
return "BookTmpl{" +
"id='" + id + '\'' +
", isbn='" + isbn + '\'' +
", title='" + title + '\'' +
", authors='" + authors + '\'' +
", rating=" + rating +
", ratingsCount=" + ratingsCount +
", publicationYear=" + year +
", language='" + language + '\'' +
", booksCount=" + booksCount +
'}';
}
}
Application.java
import Model.Book;
import data.FactoryBookData;
import data.BookData;
import data.TypeBookData;
import java.util.*;
}
public static void main(String[] args) {
BookData bookData = FactoryBookData.getTitleData(TypeBookData.CSV);
topRatedBooks.sort(Comparator.comparingDouble(Book::getRating).reversed());
topRatedBooks = topRatedBooks.subList(0,
Math.min(topRatedBooks.size(), 10));
System.out.println("Top 10 books with the highest rating: ");
for (Book book : topRatedBooks) {
System.out.println(book);
}
break;
default:
break;
}
}
while (choice != 0);
}
}
+ Define scenarios: Use natural language to define scenarios that describe the desired
behavior of the system in different situations.
+ Write user stories: Write user stories to summarize the requirements from the
customer's perspective in various situations they expect the system to operate.
+ Write tests: Write tests to ensure that the defined scenarios and user stories are met.
Tests in BDD are often written in a format close to natural language.
+ Implement code: Implement the source code to fulfill the requirements of the
defined scenarios and user stories.
+ Run tests: Execute the tests to verify that the system meets the requirements of the
scenarios and user stories.
+ Refactor code: Optimize the source code, improve the design, and restructure it to
ensure code quality after the implementation process.
import model.Book;
import model.BookImpl;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
@BeforeAll
static void setup() {
// Mocking the book data for testing
books = new ArrayList<>();
books.add(new BookImpl(1, "1234567890", "Book 1", "Author 1", 4.5,
"English", 2020));
books.add(new BookImpl(2, "0987654321", "Book 2", "Author 2", 4.2,
"Spanish", 2019));
books.add(new BookImpl(3, "9876543210", "Book 3", "Author 1", 4.8,
"English", 2021));
}
@Test
void testSearchBooks() {
List<Book> searchResults = Application.searchBooks(books, "Author 1");
assertEquals(2, searchResults.size());
assertEquals("Book 1", searchResults.get(0).getTitle());
assertEquals("Book 3", searchResults.get(1).getTitle());
}
@Test
void testSortBooksByRating() {
List<Book> sortedBooks = new ArrayList<>(books);
Application.sortBooksByRating(sortedBooks);
assertEquals(4.2, sortedBooks.get(0).getAverageRating());
assertEquals(4.5, sortedBooks.get(1).getAverageRating());
assertEquals(4.8, sortedBooks.get(2).getAverageRating());
}
@Test
void testGetTopRatedBooks() {
List<Book> topRatedBooks = Application.getTopRatedBooks(books, 2);
assertEquals(2, topRatedBooks.size());
assertEquals("Book 3", topRatedBooks.get(0).getTitle());
assertEquals("Book 1", topRatedBooks.get(1).getTitle());
}
}
Result:
Automated testing in software applications and systems provides several benefits and
has some limitations.
Unit Testing:
Benefits: Ensures accuracy of individual components, quick bug identification and fixing.
Integration Testing:
System Testing:
Benefits: Evaluates entire system behavior, ensures all components work together
correctly.
Limitations: Time-consuming, may not catch all edge cases or rare failures.
Performance Testing:
Limitations: Requires realistic test scenarios, may not uncover all performance issues.
Acceptance Testing:
Benefits: Ensures changes or updates do not introduce new defects, maintains stability.
RENFERENCE
https://www.svnhostingcomparison.com/lap-trinh-huong-doi-tuong-la-gi/
https://huongdancaidat.com/mot-so-cau-hoi-ve-oop-thuong-hoi-khi-di-phong-van/
https://topdev.vn/blog/oop-la-gi/
https://itviec.com/blog/oop-la-gi/
https://codegym.vn/blog/2022/12/26/oop-la-gi/
https://vntalking.com/nguyen-ly-solid-trong-node-js-voi-typescript.html https://laptrinhx.com/tim-hieu-
ve-nguyen-ly-solid-2609736131/ https://codelearn.io/sharing/ap-dung-nguyen-tac-solid-nhu-the-nao
https://laptrinhx.com/tim-hieu-ve-nguyen-ly-vang-solid-trong-lap-trinh-huong-doi-tuong- 1189430064/