Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Document's title* Write a title that briefly explains what it is about. Between 20 and 90, Essays (high school) of Law

Document's title* Write a title that briefly explains what it is about. Between 20 and 90 characters Description* Describe the content and the topics covered. Between 30 and 1000 characters

Typology: Essays (high school)

2022/2023

Uploaded on 12/06/2023

cao-djang-anh-quoc-btec-fpt
cao-djang-anh-quoc-btec-fpt 🇻🇳

2 documents

1 / 42

Toggle sidebar

Related documents


Partial preview of the text

Download Document's title* Write a title that briefly explains what it is about. Between 20 and 90 and more Essays (high school) Law in PDF only on Docsity! lOMoARcPSD|15992981 ASSIGNMENT 1 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date 24 /10 /2023 Date Received 1st submission 24/10/2023 Re-submission Date Date Received 2nd submission Student Name NGUYEN VAN NHAN Student ID BD00131 Class IT05201 Assessor name NGUYEN PHUONG TAM 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 Van Nhan Grading grid P1 P2 M1 M2 D1 D2 lOMoARcPSD|15992981 ❒Summative Feedbacks: Resubmission Feedbacks: Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date: 6 lOMoARcPSD|15992981 10 I. EXAMINE THE KEY COMPONENTS RELATED TO THE OBJECT-ORIENTATED PROGRAMMING PARADIGM, ANALYSING DESIGN PATTERN TYPES (LO1) 1. Examine The Characteristics Of The Object-Orientated Para- digm As Well As The Various Class Relationships (P1) 1.1. What is OOP? We can define: Object-oriented programming, or OOP for short, is a program- ming model based on the concept of Class and Object, it concretizes programming objects in which the main objects are things with properties, characteristics, action, an object consists of two pieces of information: properties and methods. OOP is used to separate a software program into simple, reusable parts. SBTEC satane wis (9g exten Object-oriented programming = Human ka : Email Verify Address Send mail Figure 1: Object-oriented programming 11 lOMoARcPSD|15992981 1.2. Class and Object 1.2.1. Object: Objects in OOP will consist of 2 main components which are: - Attribute: information about object characteristics - Methods: are the actions that the object performs For example, if we take the animals object, we can give the following properties and methods. - Properties: skin color, eyes, nose, ears, legs. - Methods: eating, barking, running. 1.2.2. Class: Class as I have defined above, objects are things that have the same properties and actions. So we can understand class in object-oriented programming can be likened to a piece of description of the state, the action of that object. In the program, objects with simi- lar properties will be grouped into the same class. The class will include properties and methods. For example, we have a class about animals, we will give the following properties and methods - Properties: skin color, eyes, nose, ears, legs. - Methods: eating, barking, running. From there we can give the objects of this class will be: dog, cat, monkey,.. 1.2.3. Class properties: Class properties are the properties of the object that the class describes. For example, animal objects have attributes such as ears, hands, and feet. These attributes are the values of the animal class. Later when objects are created from the class, the properties of the class will now become the properties of that object. 13 lOMoARcPSD|15992981 1.3.2. Inheritance: Inheritance this is a technique that allows inheriting the features that another object already has, saving time and making the code easier to see instead of having to constantly repeat the code. same very time consuming just to process a job in different sections. There are two types of inheritance as single-level inheritance and multi-level inheritance. One-level inheritance: this is an inheritance type consisting of a parent class and a child class, we will look at it in general through the following example: In the Dog class, there is no eat() method, but you can still access and use it by inheriting the method of the Animal class. 17 Figure 4 : Encapsulation lOMoARcPSD|15992981 Multi-level inheritance: is a type of inheritance consisting of many parts, for example, there are 3 classes A, B, C. A is the largest parent class, B is a child of class A but the parent of class C, C is the last subclass to have can inherit both A and B. Example: 18 Figure 5: One-level inheritance Figure 6 : Multi - level inheritance lOMoARcPSD|15992981 1.3.3. Polymorphism: Polymorphism objects of different classes can interpret the same message in different ways. You can imagine in real love it will be as follows: there are two different objects, a dog and a cat, these two animals when running with the same method of calling, they will cry but the dog says "woof woof" and the cat meows " meow". There are two types of polymorphism in the code: Method Overloading (compile time polymorphism): is how to overload methods with the same name but different parameters. We have an Overloading class, in which two methods are add but these two methods have different parameters. When we create the total variable and enter 3 parameters, so the method used is the method with 3 parameters, in the case of only entering 2 parameters, the method used is definitely the method above. 19 Figure 7 : Method Overloading SBTEC satane wis (9g exten 21 lOMoARcPSD|15992981 Figure 10: Interface 1.4. Advantages and Disavantages of OOP 1.4.1. Advantages - Easy to manage code - Easy to scale the project - Improve software maintainability - Improve software development performance - Reduce development costs - Improved software maintainability (Modularity, Extensibility, Reusability...) - Reusable OOP code, which saves resources. - improved error code faster repair time. - Partitioning tasks help the object in the project. - Program safety can be built by hiding data. - It has the ability to set graphs for objects. 22 lOMoARcPSD|15992981 - Allows to classify objects into different classes. - System objects can be easily upgraded. - Code redundancy can be eliminated using inheritance. - Code must be open by the way used again. - The big-module can be achieved. - Utrust works enhanced data exception. - Flexible system concepts. - Separate necessary technical points from implementation using information hiding. 1.4.2. Disavantages - The program is slow and has a larger capacity - Must study intensively - Depends on whether the problem type is suitable for OOP or not - not digital device friendly. - difficult to reach for beginners. - not suitable use it with the simple problem. 23 lOMoARcPSD|15992981 2.2.2. Class Diagram We will create a SingleObject class. The SingleObject class has its constructor pri- vate and has a static instance of itself. The SingleObject class provides a static method to expose its static instance to the outside world. SingletonPatternDemo , our demo class will use the SingleObject class to get a SingleObject object. 2.2.3. Code Demo Create a Singleton Class. SingleObject.java 25 Figure 11 : Class diagram lOMoARcPSD|15992981 Get the only object from the singleton class. 26 Figure 13 : SingletonPatternDemo.java Figure 12 : SingleObject.java lOMoARcPSD|15992981 2.2.4. Advantages and Disadvantages Advantages: The three most outstanding advantages of Singleton are the characteristics we have mentioned many times in the article, which are: - You can be sure that each class has only one instance. - You can access the instance anywhere and anytime - Singletons only initialize when you call them for the first time (call when initialize then). Disadvantages: - Violation of the Single Responsibility Principle - the principle of single duty, a pat- tern solves 2 problems at the same time. - The Singleton pattern can hide bad design for instances when the components in the program know each other well. - Singleton requires special handling in a multithreaded field, so that multiple threads don't create a Singleton object more than once. - Singleton is often considered "Evil" by longtime programmers, because Singleton creates too many dependencies, cannot use polymorphism, and easily creates bugs that make them debug "all night". 2.3. Adapter Design Pattern (Structural Pattern) 2.3.1. Definition of Adapter Design Pattern The adapter pattern is a member of the structural pattern family that addresses the overall system's structure by concentrating on the connections between entities and compo- nents to facilitate simpler interactivity. The adapter pattern functions as a bridge to connect new parts to legacy systems without changing the code, enabling the collaboration of uncon- nected interfaces. An adapter is the thing that is attached to the interface. 27 lOMoARcPSD|15992981 Figure 17 : code demo for Adapter Design Pattern 2.3.4. Explain Code Demo We have a MediaPlayer interface and a concrete AudioPlayer class that implements MediaPlayer. AudioPlayer can play mp3 format audio files by default. Figure 18 : Main of code demo for Adapter Design Pattern lOMoARcPSD|15992981 We have another interface AdvancedMediaPlayer and concrete classes that imple- ment the AdvancedMediaPlayer interface. These classes can play vlc and mp4 files. We want to create AudioPlayer to play other formats. To achieve this, we have cre- ated a MediaAdapter class, which implements the MediaPlayer interface and uses Ad- vancedMediaPlayer objects to play the required format. AudioPlayer uses the adapter of the MediaAdapter class to pass the desired audio type without knowing the actual class can play the desired format. AdapterPatternDemo, our demo class will use the AudioPlayer class to play different formats. 2.3.5. Advantages and Disadvantages Advantages - Single Responsibility Principle: It is possible to separate the interface or the code that converts data from the main business logic of the program. - Open/Closed Principle: Keeps code from being affected by changes or new version updates from APIs or third-party services (changing function names, class names, etc.) Disadvantages - The overall complexity of the code increases because you need to introduce a new set of Templates and classes. Sometimes it's simpler to change the service layer to match the rest of your code. Figure 19 : Explain code demo lOMoARcPSD|15992981 2.4. Iterator Design Pattern (Behavior Pattern) 2.4.1. Definition of Iterator Design Pattern. One of the models in the collection of behaviour models is the repetition model. It serves as a means of sequentially accessing a composite object's components without having to develop a unique access method for the composite object. In other words, iterators are made to make it possible to process many sorts of collections without having to fully com- prehend their internal workings by using the same approach to access the collection's ele- ments in a preset fashion. The division of responsibility between classes is advantageous when the class changes. It will be challenging to change the code if a class contains an excessive number of items. The "single responsibility" category will only have one explanation for changes when they take place. The iterator pattern's use cases include: Without knowing the contents of the executable files, you must access the contents of the collection's objects. - Facilitates access to a wide range of collection types. - Create a special interface for iterating the collection's elements. 2.4.2. Class Diagram 2.4.3. Code Demo Create interfaces Figure 20 : Class diagram lOMoARcPSD|15992981 2.4.5. Advantages and Disadvantages Advantages - Ensure the Single responsibility principle (SRP): we can separate the implementation of the collection methods and the iterator of the elements by individual classes. - Ensure Open/Closed Principle (OCP): we can implement new collection types and new iterators, and then pass them into existing code without breaking any rules. - We can access the same set in parallel because each iterator object contains its own state. - In a few cases, you can delay a repetition and resume it as needed. Disadvantages - Using an iterator can be less efficient than traversing the collection's elements di- rectly. - It may not be necessary if the application only works with simple collections. lOMoARcPSD|15992981 II. DESIGN A SERIES OF UML CLASS DIAGRAMS (LO2) 1. Design And Build Class Diagrams Using A UML Tool (P2) 1.1. Definition of Class Diagrams A class diagram is a type of static structure diagram that describes the structure of a system by showing the system's classes, their properties, operations, and relationships be- tween objects. The class diagram is the main building block of the object-oriented model. Summarizing the above, we can understand the following ideas: • Class diagrams describe the types of objects in the system and the different types of relationships that exist between them. • Is a modeling technique that exists in all object-oriented development methods. • The most commonly used diagram in UML and closest to programmers. • Help developers communicate with each other and understand each other's ideas 1.2. Access Modifier In Class Diagram Used to specify the scope of access for the Attribute and Operation of a class (Grant permis- sion to other classes to use the Attribute and Operation of this class). For access range se- lection: • Private (-): Only the objects created from this class can be used. • Public (+): Any object can use it. • Protected (#): Only objects created from this class and classes that inherit from this class can be used. • Package/Default (~): Objects created from the class in the same package can be used. 37 lOMoARcPSD|15992981 1.3. Relationship in class diagram Used to represent each relationship between objects created from one class and ob- jects created from other classes in the class diagram. 4 types of Relationships: • Inheritance: A class inherits from another class. • Association: 2 classes that are related but do not specify the relationship. • Composition: If the object created from class A is lost, the object created from class B will be lost. • Agreegation: The object created from class A is lost, the object created from class B still exists independently. Figure 25 : Relationship in class diagram lOMoARcPSD|15992981 1.5. Use UML For Real Scenario 1.5.1. Scenario 1.5.2. Use Case Figure 28 : Account Management Figure 29 : Use case of Teacher lOMoARcPSD|15992981 1.5.3. Class Diagram For The System ❖ Admin class Admin class declares Admin properties such as: ID, Name, Password. Admin class has methods like: Login(), Logout(), addTeacher(), addStudent(),... ❖ Teacher class Figure 30 : Use case of Student Figure 31 : Class diagram for system lOMoARcPSD|15992981 The Teacher class declares the Teacher's properties such as: ID, Name, address, PhNo. The Teacher class has methods such as: prepareTestPaper(), markAttendance(), checkPaper,... ❖ TestPaper class TestPaper class declares TestPaper calculations such as: ID, name, duration, classID. The TestPaper class has methods viewTestPaper(), deleteTestPaper(). ❖ Student class The Student class declares the Student's calculations such as: ID, name,address,PhNo . The Student class has methods addminsionForm(), getEnrolled(), writeExam(). 1.6. UML and IDE 1.6.1. Tool for drawing UML In our UML design, we used the Lucidchart tool to draw. Lucidchart is an HTML-5- based UML engine that also provides real-time collaboration capabilities. It allows you to create a simple diagram for complex engineering diagrams. In addition, the ability to inte- grate applications allows us to incorporate other productivity tools our team is using such as Jira, GitHub, Confluence, Salesforce, and more. Undoubtedly, the application integration will boost and enhance the productivity of our team. Figure 32 : Class diagram tool lOMoARcPSD|15992981 CONCLUSION Advanced programming requires knowledge of object-oriented programming, data structures, and complex algorithms. It also includes multithreading management, exception handling, performance optimization, and security insights. Writing clean code and using frameworks/libraries effectively is important. Finally, continuous learning in a software development environment is indispensable to keep up with the rapid evolution of technology. lOMoARcPSD|15992981 REFERENCES 1. "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin: This book focuses on writing clean, maintainable, and high-quality code. 2. "Design Patterns: Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides: This classic book introduces various design patterns that can enhance your software architecture. 3. "Introduction to Algorithms" by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein: This book provides a comprehensive introduction to data structures and algorithms. 4. "Java Concurrency in Practice" by Brian Goetz: For Java programmers, this book is an excellent resource for understanding concurrency and multithreading. 5. "Effective Java" by Joshua Bloch: This book provides practical advice on writing effective and efficient Java code. SBTEC satane wis (9g exten
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved