Advanced Programming
Advanced Programming
Contents
Part 1.....................................................................................................................................................5
Produce a presentation and there will be viva for following too:.........................................................5
Examine the characteristics of the object-orientated paradigm as well as the various class
relationships..........................................................................................................................................5
Determine a design pattern from each of the creational, structural and behavioral pattern
types......................................................................................................................................................5
Analyze the relationship between the object-orientated paradigm and design patterns.............5
NOTE: IN part 1, Screenshot of presentation slides as well as video of your presentation is
required.................................................................................................................................................5
Presentation task:..............................................................................................................................5
Introduction.....................................................................................................................................16
Object-Oriented Programming:........................................................................................................16
Principles of object-oriented programming......................................................................................17
1. Encapsulation:.........................................................................................................................18
2. Abstraction..............................................................................................................................18
Advantages of Object-Oriented Programming...........................................................................19
Disadvantages of Object-Oriented Programming......................................................................19
How can Knowledge of OOP help in Career Growth?...............................................................19
How OOP is used in Software Development?...................................................................................20
Characteristic of Object Oriented Programming...............................................................................21
Class:...........................................................................................................................................22
Object:.........................................................................................................................................22
Encapsulation:.............................................................................................................................22
Abstraction:.................................................................................................................................24
Polymorphism:............................................................................................................................25
Inheritance:.................................................................................................................................26
Exception Handling.....................................................................................................................27
Oop Relationships Between Classes:................................................................................................27
Types of Class relationship in oop:....................................................................................................29
Collaboration...............................................................................................................................29
Composition.................................................................................................................................32
Inheritance.......................................................................................................................................37
Advance programming
Interfaces:....................................................................................................................................38
Abstract Class..............................................................................................................................39
Partial classes:.............................................................................................................................40
Delegates:.....................................................................................................................................41
Events:.........................................................................................................................................42
Generics:......................................................................................................................................43
Conclusion:.......................................................................................................................................44
Part 2...................................................................................................................................................47
Design a series of UML class diagram:.......................................................................................47
Design and build class diagrams using a UML tool....................................................................47
Define class diagrams for specific design patterns using a UML tool........................................47
Define/refine class diagrams derived from a given code scenario using a UML tool.................47
Introduction.....................................................................................................................................47
Design and build class diagrams using a UML tool............................................................................47
UML Class Diagram...........................................................................................................................47
Benefits of UML class diagrams..................................................................................................48
Basic components of a class diagram................................................................................................48
Member access modifiers............................................................................................................48
How to make a Uml class diagram....................................................................................................49
Why UML.........................................................................................................................................49
Uml class diagram for library management system:.........................................................................50
Conclusion:.......................................................................................................................................52
Part 3...................................................................................................................................................53
Create a lab report to show that you have implement code applying design pattern:...............53
Build an application derived from UML class diagrams............................................................53
Develop code that implements a design pattern for a given purpose.........................................53
Evaluate the use of design patterns for the given purpose specified in M3................................53
Table of content:..............................................................................................................................54
Report Introduction..........................................................................................................................59
Build an application derived from UML class diagrams.....................................................................59
Screenshot of designing pattern of application building derived from UML class diagrams:.............59
Login:...........................................................................................................................................60
Dashboard:..................................................................................................................................60
Advance programming
Users form:..................................................................................................................................60
Book category form:....................................................................................................................61
Books:..........................................................................................................................................62
Issue:............................................................................................................................................62
Returns:.......................................................................................................................................65
Search:.........................................................................................................................................65
Report Conclusion............................................................................................................................66
Part 4...................................................................................................................................................69
Write an article about your investigation on scenarios with respect to design pattern.............69
Discuss a range of design patterns with relevant examples of creational, structural and
behavioral pattern types.....................................................................................................................69
Reconcile the most appropriate design pattern from a range with a series of given scenarios..69
Critically evaluate a range of design patterns against the range of given scenarios with
justification of your choices................................................................................................................69
Article Introduction..........................................................................................................................69
Discuss a range of design patterns with relevant examples of creational, structural and behavioral
pattern types....................................................................................................................................69
Design Patterns................................................................................................................................69
Uses of Design Patterns...............................................................................................................70
Types of design pattern:...................................................................................................................70
1. Creational design patterns:.................................................................................................70
Range of creational pattern:.......................................................................................................71
Example with code:.....................................................................................................................71
2. Structural design patterns:..................................................................................................76
Range of Structural Design Pattern:...........................................................................................76
Example Code:............................................................................................................................76
3. Behavioral design patterns:.................................................................................................78
Range of Behavioral Design Pattern:..........................................................................................78
Code example:.............................................................................................................................79
Article Conclusion.............................................................................................................................81
References:.......................................................................................................................................83
Advance programming
Part 1
Determine a design pattern from each of the creational, structural and behavioral
pattern types.
Presentation task:
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Advance programming
Introduction
According to the current scenario, Cosmos International College is newly setup yet reputed
college in Pokhara with an aim to provide quality management education to its students. In past
years, the students record were handled using the excel file method. The admin had hard time for
record management after the increase in significant amount of students and the newly established
library system. As being a full stack software developer, the college has provided a project for
me to create a software for the “Library Management” which will be able to handle all of these
student, staff and book records with some other specific user requirements. In this part, I will
simply demonstrate the ideas of object oriented programming, design patterns, analyze and
present their relationships and finally represent their application in our software.
There are many OOP languages, with the most popular ones being class-based, where objects
will be an instance of a class. A class is a container for data and procedures, also known as data
members and member functions. Let us consider an example of an object as a car. A car has
attributes like color, brand name, fuel capacity, etc. and it has methods to represent the behavior
of a car like a start, accelerate, break, etc. A class is a blueprint of attributes and methods and
does not occupy space, until and unless an object for that class is made. (EDUCBA, 2020)
Example:
class car
char colour[20];
};
void main()
1. Encapsulation:
Binding of data and methods into a single unit is called encapsulation. Encapsulation is
accomplished when each object inside the class keeps its state private. The data inside this unit is
Advance programming
not accessible by outside objects and only those functions inside this unit are able to access it.
Thus, the object manages its state with the help of its methods, and to communicate with this
object, we will require the help of the public methods of this class.
2. Abstraction
Abstraction is an extension of encapsulation. It means providing only the necessary information
to the outside world while hiding the internal details of implementation. It reveals only the
appropriate operations for other objects. The advantage of this is that we can change the
implementation without affecting the class, as the method interface remains the same.
Let us take the example of a calculator, which takes the input from us, and on the press of a
button, gives us the desired output, while sparing us the internal details of how it has arrived at
that answer. (EDUCBA, 2020)
3. Inheritance
Often, objects are similar in functionality, sharing part of the logic but differing in the rest. So
how do we reuse the common logic and separate the different logic? This can be achieved by
inheritance. In inheritance, we create a new class called as child class which is derived from the
existing class called the parent class, thus forming a hier0archy of classes. The child class reuses
the data fields and methods that it requires from the parent class, and implements its unique
functionality on its own.
For example, a vehicle can be a parent class, from which we can derive child classes like Bike
and Car. They share the common properties of being able to run on fuel and carry passengers but
differ in the number of passengers they can carry and more such properties.
4. Polymorphism
Polymorphism is the ability to take more than one form. Suppose we have a parent class and a
few of its child classes. Now we want to use attributes from both the parent and the child classes,
so how will it be achieved? This can be done using Polymorphism. In Polymorphism, abstract
entities are executed in multiple ways. It gives a way to consume a class exactly like the parent
class, such that there is no confusion with mixing the type of classes, and each child class
Advance programming
continues to keep its methods the way it was. This can be done by reusing a parent interface so
that the child class can implement these methods in their own version. (EDUCBA, 2020)
Disadvantages of Object-Oriented Programming
How can Knowledge of OOP help in Career Growth?
Many of the major trending languages these days like Java and Ruby, use Object-oriented
programming concepts. OOP languages help in writing software for applications such as mobile,
web and gaming applications. There are high earnings in these fields, like the best job
opportunities for programmers to lie in these fields. It is easy to move into various technologies
and languages with the basics of OOP, and thus this widens our career prospects. One drawback
in this happens to be expertise. Usually, companies look for practical experience in OOP
Advance programming
In any complexity of software development, OOP is the best to solve the issue. These are the
areas where OOP is used (Buyya et al, 2009):
Image processing
Pattern recognition
Intelligent systems
Mobile computing
Advance programming
Parallel computing
OOP just helps us to load the real world problem into software which can be modified in
different ways depending on the needs. Once a code generated for any software can be used
again and again to serve other applications with same functions. This helps in saving lots of time
for the programmers and also helps in making the program flexible so that it can be easily
modified when there is need.
Object Oriented programming is a programming style that is associated with the concept of
Class, Objects and various other concepts revolving around these two, like Inheritance,
Polymorphism, Abstraction, Encapsulation etc.
Advance programming
Every Human being(Male or Female) has two legs, two hands, two eyes, one nose, one heart etc.
There are body parts that are common for Male and Female, but then there are some specific
body parts, present in a Male which are not present in a Female, and some body parts present in
Female but not in Males. All Human Beings walk, eat, see, talk, hear etc. Now again, both Male
and Female, performs some common functions, but there are some specifics to both, which is not
valid for the other. For example : A Female can give birth, while a Male cannot, so this is only
for the Female. Human Anatomy is interesting, isn't it? But let's see how all this is related to C++
and OOPS. Here we will try to explain all the OOPS concepts through this example and later we
will have the technical definitons for all this.
Class: It is similar to structures in C language. Class can also be defined as user defined data
type but it also contains functions in it. So, class is basically a blueprint for object. It declare &
defines what data variables the object will have and what operations can be performed on the
class's object. Here we can take Human Being as a class. A class is a blueprint for any functional
entity which defines its properties and its functions. Like Human Being, having body parts, and
performing various actions. (Vegibit.com, 2020)
A Class is a user-defined data-type which has data members and member functions.
Advance programming
Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions define
the properties and behaviour of the objects in a Class.
In the above example of class Car, the data member will be speed limit, mileage etc and
member functions can apply brakes, increase speed etc.
We can say that a Class in C++ is a blue-print representing a group of objects which shares
some common properties and behaviours.
Object: Objects are the basic unit of OOP. They are instances of class, which have data
members and uses various member functions to perform tasks. Object take up space in memory
and have an associated address like a record in pascal or structure or union in C. When a
program is executed the objects interact by sending messages to one another. Each object
contains data and code to manipulate the data. Objects can interact without having to know
details of each other’s data or code, it is sufficient to know the type of message accepted and
type of response returned by the objects.
Encapsulation: This concept is a little tricky to explain with our example. Our Legs are binded
to help us walk. Our hands, help us hold things. This binding of the properties to functions is
called Encapsulation. It can also be said data binding. Encapsulation is all about binding the data
variables and functions together in class.
Consider a real-life example of encapsulation, in a company, there are different sections like the
accounts section, finance section, sales section etc. The finance section handles all the financial
transactions and keeps records of all the data related to finance. Similarly, the sales section
handles all the sales-related activities and keeps records of all the sales. Now there may arise a
situation when for some reason an official from the finance section needs all the data about sales
in a particular month. In this case, he is not allowed to directly access the data of the sales
section. He will first have to contact some other officer in the sales section and then request him
to give the particular data. This is what encapsulation is. Here the data of the sales section and
the employees that can manipulate them are wrapped under a single name “sales section”.
(GeeksforGeeks, 2019)
Advance programming
Abstraction: Abstraction refers to showing only the essential features of the application and
hiding the details. In C#, classes can provide methods to the outside world to access & use the
data variables, keeping the variables hidden from direct access, or classes can even declare
everything accessible to everyone, or maybe just to the classes inheriting it. This can be done
using access specifiers. Abstraction means, showcasing only the required things to the outside
world while hiding the details. Continuing our example, Human Being's can talk, walk, hear, eat,
Advance programming
but the details are hidden from the outside world. We can take our skin as the Abstraction factor
in our case, hiding the inside mechanism.
Abstraction using Classes: We can implement Abstraction in C++ using classes. The
class helps us to group data members and member functions using available access
specifiers. A Class can decide which data member will be visible to the outside world and
which is not.
Abstraction in Header files: One more type of abstraction in C++ can be header files. For
example, consider the pow() method present in math.h header file. Whenever we need to
calculate the power of a number, we simply call the function pow() present in the math.h
header file and pass the numbers as arguments without knowing the underlying algorithm
according to which the function is actually calculating the power of numbers.
Polymorphism: It is a feature, which lets us create functions with same name but different
arguments, which will perform different actions. That means, functions with same name, but
functioning in different ways. Or, it also allows us to redefine a function to provide it with a
completely new definition. You will learn how to do this in details soon in coming lessons.
Polymorphism is a concept, which allows us to redefine the way something works, by either
changing how it is done or by changing the parts using which it is done. Both the ways have
different terms for them. (Vegibit.com, 2020)
Overloading: If we walk using our hands, and not legs, here we will change the parts
used to perform something. Hence this is called Overloading.
Overriding: And if there is a defined way of walking, but I wish to walk differently, but
using my legs, like everyone else. Then I can walk like I want, this will be called
as Overriding.
Example: Suppose we have to write a function to add some integers, some times there are 2
integers, some times there are 3 integers. We can write the Addition Method with the same name
having different parameters, the concerned method will be called according to parameters.
Advance programming
Inheritance: Inheritance is a way to reuse once written code again and again. The class which is
inherited is called the Base class & the class which inherits is called the Derived class. They are
also called parent and child class. So when, a derived class inherits a base class, the derived class
can use all the functions which are defined in base class, hence making code reusable.
Considering HumanBeing a class, which has properties like hands, legs, eyes etc, and functions
like walk, talk, eat, see etc. Male and Female are also classes, but most of the properties and
functions are included in HumanBeing, hence they can inherit everything from
class HumanBeing using the concept of Inheritance.
Advance programming
Exception Handling
Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at
runtime. (Vegibit.com, 2020)
2{
4
5 return order;
6}
In addition, the AddressRepository Class uses an instance of the Address Class when retrieving
or saving an Address. The CustomerRepository Class uses an instance of the Customer Class
when retrieving or saving a Customer. So you can see how this type of relationship works.
2{
3 this.CustomerId = customerId;
5}
6
Advance programming
Types of Class relationship in oop: There are many types of relationships in object-oriented
programming. The first one we will look at is the collaboration relationship. In a collaboration
relationship, you often refer to it as a “Uses A” relationship. This is because you can think of one
class using another class. The next type of relationship we’ll look at is a composition
relationship. A composition relationship can be referred to using a “Has A” relationship type.
The idea of composition is that an object can be composed of other objects. An Order has a
Customer. An Order also has a OrderItem. The last relationship type we will look at is
Inheritance, or a “Is A” relationship. A CommercialCustomer is a Customer or a
ConsumerCustomer is a Customer. (Vegibit.com, 2020)
Collaboration
Here we have a diagram of a collaboration type relationship between classes. The
OrderRepository “uses a” Order object to populate on a Retrieve, and to serialize on a save. The
same goes for the CustomerRepository “using a” Customer object and a ProductRepository
“using a” Product object. (Vegibit.com, 2020)
Advance programming
In this code we can see how the CustomerRepository class uses a Customer class. Inside of the
Retrieve() method, we see how a new Customer object is created. That object is then populated
with data. In our case it is simply hard-coded, but you could imagine this data coming from a
database.
The CustomerRepository uses a Customer object once again in the Save() method. In order for
that method to do its job, it needs to accept a Customer object as a parameter. Inside that method,
the data from the Customer object would be used to persist to the database. The repository
classes use an entity class to populate the entity, or serialize the entity depending on if it is being
used in the Retrieve() or Save() methods. This pattern holds true for the other repository classes
we have been working with as well.
1 using System;
Advance programming
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace CRMBIZ
8 {
10 {
12 {
14
15 if (customerId == 1)
16 {
17 customer.EmailAddress = "[email protected]";
18 customer.FirstName = "Susan";
19 customer.LastName = "Smith";
20 }
21 return customer;
22 }
23
Advance programming
25 {
27 }
28
30 {
31 return true;
32 }
33 }
34 }
You can spot a collaboration type relationship any time you see a class use an instance of another
class to perform an operation in the application.
Composition
Composition is another key relationship type in object-oriented programming. A composition
relationship exists when an object from one class, is made up of or composed of one or more
objects from another class. It is also known as a “Has A” type relationship. In our CRM
application this type of relationship exists between the Customer class and the Address class. A
Customer “Has A” Address. (Vegibit.com, 2020)
Advance programming
In the diagram above we show some composition relationships. The Customer class “Has A”
Address. The Order object is also composed of other objects. Every Order has a Customer, has
an Address, and has an OrderItem. Additionally, each OrderItem “Has A” Product. So we can
kind of see how a given object can be composed of other objects to make the application work.
The Composition relationship can be accomplished using references in our code, which leverage
class properties. Let’s have a look at the Customer class to see how this works. First we’ll look
at the composition relationship between the Customer class and Address class. In the below
code, we have highlighted a specific property. The Customer object is composed of one or more
Address objects. Why one or more? Because there could be a home address or a work address.
So we use a property of type List to allow for one or more Address objects to help compose a
Customer object. A property declaration in the Customer class establishes the composition
relationship between the Customer class and the Address class. Also note that since this property
is a List, it must be initialized in the constructor like we also see below. If it is not, it would
cause a null value exception.
1 using System;
Advance programming
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace CRMBIZ
8 {
10 {
11 public Customer()
12 : this(0)
13 {
14
15 }
16
18 {
19 this.CustomerId = customerId;
21 }
22
24
27
30 {
31 get
32 {
33 return _lastName;
34 }
35 set
36 {
37 _lastName = value;
38 }
39 }
40
42
44
46
48 {
49 get
50 {
52 if (!string.IsNullOrWhiteSpace(FirstName))
53 {
54 if (!string.IsNullOrWhiteSpace(fullName))
55 {
57 }
58 fullName += FirstName;
59 }
60 return fullName;
61 }
62 }
63
65 {
67
Advance programming
70
71 return isValid;
72 }
73 }
74 }
Inheritance
In object oriented programming we also have the Inheritance style of relationship. In Inheritance
you have an “Is A” type of relationship. Inheritance allow you to build a class that inherits the
members of its parent or base class. This allows you to define a more specific type of class. So
consider the Customer class. We might have Business customers and Education customers. They
are both customers, but different kinds of customers. This allows for code reuse since child
classes that inherit members from their parent class, are using the properties and methods already
defined in the parent class. (Vegibit.com, 2020)
Advance programming
When using inheritance in C#, you can only directly inherit from one class. You can however set
up inheritance chains if you like. In other words you could have a Customer class, and an
Education class that inherits from Customer. Then, you could set up a College class, that inherits
from the Education class.
Interfaces: In general, an interface is a device or a system that unrelated entities use to interact.
According to this definition, a remote control is an interface between you and a television set, the
English language is an interface between two people, and the protocol of behavior enforced in
the military is the interface between people of different ranks. Within the Java programming
language, an interface is a type, just as a class is a type. Like a class, an interface defines
methods. Unlike a class, an interface never implements methods; instead, classes that implement
the interface implement the methods defined by the interface. A class can implement multiple
interfaces. (Vegibit.com, 2020)
The bicycle class and its class hierarchy define what a bicycle can and cannot do in terms of its
"bicycleness." But bicycles interact with the world on other terms. For example, a bicycle in a
store could be managed by an inventory program. An inventory program doesn’t care what class
of items it manages, as long as each item provides certain information, such as price and tracking
number. Instead of forcing class relationships on otherwise unrelated items, the inventory
program sets up a protocol of communication. This protocol comes in the form of a set of
method definitions contained within an interface. The inventory interface would define, but not
implement, methods that set and get the retail price, assign a tracking number, and so on.
To work in the inventory program, the bicycle class must agree to this protocol by implementing
the interface. When a class implements an interface, the class agrees to implement all the
methods defined in the interface. Thus, the bicycle class would provide the implementations for
the methods that set and get retail price, assign a tracking number, and so on. You use an
interface to define a protocol of behavior that can be implemented by any class anywhere in the
class hierarchy. Interfaces are useful for the following: (C-sharpcorner.com, 2019)
Advance programming
Abstract Class
An abstract class is a class that is declared abstract — it may or may not include abstract
methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract class
may have static fields and static methods. When an abstract class is subclassed, the subclass
usually provides implementations for all of the abstract methods in its parent class. However, if it
does not, then the subclass must also be declared abstract. (Vegibit.com, 2020)
An abstract method is a method that is declared without an implementation (without braces and
followed by a semicolon), like this:
Consider using abstract classes if any of these statements apply to your situation:
Partial classes: A partial class is a special feature of C#. It provides a special ability to
implement the functionality of a single class into multiple files and all these files are combined
into a single class file when the application is compiled. A partial class is created by using
Advance programming
a partial keyword. This keyword is also useful to split the functionality of methods, interfaces, or
structure into multiple files. (Vegibit.com, 2020)
Important points:
When you want to chop the functionality of the class, method, interface, or structure into
multiple files, then you should use partial keyword and all the files are mandatory to
available at compile time for creating final file.
The partial modifier can only present instantly before the keywords like struct, class, and
interface.
Every part of the partial class definition should be in the same assembly and namespace,
but you can use different source file name.
Every part of the partial class definition should have the same accessibility like private,
protected, etc.
If any part of the partial class is declared as an abstract, sealed, or base, then the whole
class is declared of the same type.
The user is also allowed to use nested partial types.
Dissimilar part may have dissimilar base types, but the final type must inherit all the base
types.
Example: Here, we are taking a class named as Geeks and split the definition of Geeks class into
two different files named as Geeks1.cs, and Geeks2.cs as shown below:
Advance programming
In Geeks1.cs, and Geeks2.cs, a partial class is created using the partial keyword and each file
contains different functionality of Geeks class
Delegates: A delegate is a type that represents references to methods with a particular parameter
list and return type. When you instantiate a delegate, you can associate its instance with any
method with a compatible signature and return type. You can invoke (or call) the method through
the delegate instance.
Delegates are used to pass methods as arguments to other methods. Event handlers are nothing
more than methods that are invoked through delegates. You create a custom method, and a class
such as a windows control can call your method when a certain event occurs. The following
example shows a delegate declaration. Delegation is an important design pattern itself. It's used a
lot in Objective C and NEXTSTEP programming as an alternative to mandatory inheritance from
a complex framework and multiple inheritance.
If B is a subclass of A then sending B a message for something in A's interface means that B can
re-use the implemtation found in A. Delegation uses composition to put re-use the
implementation from A. B's interface can be extended to have some of the same functionality of
A. But when a B object is sent a message corresponding to a method in A's type, it forwards the
message to an A object. The aggregation design we saw earlier for implementing a Set in terms
of a List is an example of the use of delegation. (Vegibit.com, 2020)
Properties:
Delegates are similar to C++ function pointers, but delegates are fully object-oriented,
and unlike C++ pointers to member functions, delegates encapsulate both an object
instance and a method.
Delegates can be chained together; for example, multiple methods can be called on a
single event.
Methods do not have to match the delegate type exactly. For more information, see Using
Variance in Delegates.
C# version 2.0 introduced the concept of anonymous methods, which allow code blocks
to be passed as parameters in place of a separately defined method. C# 3.0 introduced
lambda expressions as a more concise way of writing inline code blocks. Both anonymous
methods and lambda expressions (in certain contexts) are compiled to delegate types.
Together, these features are now known as anonymous functions. For more information
about lambda expressions, see Lambda expressions.
Events: Events enable a class or object to notify other classes or objects when something of
interest occurs. The class that sends (or raises) the event is called the publisher and the classes
that receive (or handle) the event are called subscribers.
In a typical C# Windows Forms or Web application, you subscribe to events raised by controls
such as buttons and list boxes. You can use the Visual C# integrated development environment
(IDE) to browse the events that a control publishes and select the ones that you want to handle.
The IDE provides an easy way to automatically add an empty event handler method and the code
to subscribe to the event. For more information, see How to: Subscribe to and Unsubscribe from
Events. (Vegibit.com, 2020)
Events Overview
The publisher determines when an event is raised; the subscribers determine what
action is taken in response to the event.
An event can have multiple subscribers. A subscriber can handle multiple events from
multiple publishers.
Advance programming
Events are typically used to signal user actions such as button clicks or menu selections
in graphical user interfaces.
When an event has multiple subscribers, the event handlers are invoked synchronously
when an event is raised. To invoke events asynchronously, see Calling Synchronous
Methods Asynchronously.
Generics: it is a class which allows the user to define classes and methods with the placeholder.
Generics were added to version 2.0 of the C# language. The basic idea behind using Generic is to
allow type (Integer, String, … etc and user-defined types) to be a parameter to methods, classes,
and interfaces. A primary limitation of collections is the absence of effective type checking. This
means that you can put any object in a collection because all classes in the C# programming
language extend from the object base class. This compromises type safety and contradicts the
basic definition of C# as a type-safe language. In addition, using collections involves a
significant performance overhead in the form of implicit and explicit type casting that is required
to add or retrieve objects from a collection.
To address the type safety issue, the .NET framework provides generics to create classes,
structures, interfaces, and methods that have placeholders for the types they use. Generics are
commonly used to create type-safe collections for both reference and value types.
The .NET framework provides an extensive set of interfaces and classes in the
System.Collections.Generic namespace for implementing generic collections.
Generics in C# is its most powerful feature. It allows you to define the type-safe data structures.
This out-turn in a remarkable performance boost and high-grade code, because it helps to reuse
data processing algorithms without replicating type-specific code. Generics are similar to
Advance programming
templates in C++ but are different in implementation and capabilities. Generics introduces the
concept of type parameters, because of which it is possible to create methods and classes that
defers the framing of data type until the class or method is declared and is instantiated by client
code. Generic types perform better than normal system types because they reduce the need for
boxing, unboxing, and type casting the variables or objects. (Vegibit.com, 2020)
Features of Generics
You can create generic collection classes. The .NET Framework class library contains
several new generic collection classes in the System.Collections.Generic namespace.
You may use these generic collection classes instead of the collection classes in
the System.Collections namespace.
You can create your own generic interfaces, classes, methods, events, and delegates.
You may create generic classes constrained to enable access to methods on particular
data types.
You may get information on the types used in a generic data type at run-time by means
of reflection.
Conclusion: in this task firstly, I have done presentation about the relationship between oop and
design pattern. After that I have mention the definition of oop as well as their characteristic,
properties and relationship between oop and different classes. I have also attaches the screenshot
of coding in characteristic example.
Advance programming
Advance programming
Part 2
Define class diagrams for specific design patterns using a UML tool.
Define/refine class diagrams derived from a given code scenario using a UML tool.
Introduction
In the previous task, I have described about the different programming paradigms which are
quite useful for project development. Now, in this task I will describe about the class diagrams,
UML tools and design class diagrams from those UML tools for the project. This will also
include about the purpose of class diagram for the project planning, class relationships and
operations with various examples. The use of class diagrams are quite important if we seek the
long term development of project. Such processes will guide the developers to use the design in
specific terms.
The Unified Modeling Language (UML) can help you model systems in various ways. One of
the more popular types in UML is the class diagram. Popular among software engineers to
document software architecture, class diagrams are a type of structure diagram because they
describe what must be present in the system being modeled. No matter your level of familiarity
with UML or class diagrams, our UML software is designed to be simple and easy to use.
The various components in a class diagram can represent the classes that will actually be
programmed, the main objects, or the interactions between classes and objects.
The class shape itself consists of a rectangle with three rows. The top row contains the name of
the class, the middle row contains the attributes of the class, and the bottom section expresses the
methods or operations that the class may use. Classes and subclasses are grouped together to
show the static relationship between each object. (Fakhroutdinov, 2020)
Class diagrams offer a number of benefits for any organization. Use UML class diagrams to:
Illustrate data models for information systems, no matter how simple or complex.
Better understand the general overview of the schematics of an application.
Visually express any specific needs of a system and disseminate that information
throughout the business.
Create detailed charts that highlight any specific code needed to be programmed and
implemented to the described structure.
Provide an implementation-independent description of types used in a system that are
later passed between its components.
Upper section: Contains the name of the class. This section is always required, whether
you are talking about the classifier or an object.
Middle section: Contains the attributes of the class. Use this section to describe the
qualities of the class. This is only required when describing a specific instance of a class.
Bottom section: Includes class operations (methods). Displayed in list format, each
operation takes up its own line. The operations describe how a class interacts with data.
Advance programming
All classes have different access levels depending on the access modifier (visibility). Here are
the access levels with their corresponding symbols:
Public (+)
Private (-)
Protected (#)
Package (~)
Derived (/)
Static (underlined)
In Lucidchart, creating a class diagram from scratch is surprisingly simple. Just follow these
steps: (Fakhroutdinov, 2020)
2. Enable the UML shape library. On the left side of the Lucidchart editor, click "Shapes."
Once you're in the Shape Library Manager, check "UML" and click "Save."
3. From the libraries you just added, select the shape you want and drag it from the toolbox
to the canvas.
4. Model the process flow by drawing lines between shapes while adding text.
Why UML
As the strategic value of software increases for many companies, the industry looks for
techniques to automate the production of software and to improve quality and reduce cost and
time-to-market. These techniques include component technology, visual programming, patterns
and frameworks. Businesses also seek techniques to manage the complexity of systems as they
increase in scope and scale. In particular, they recognize the need to solve recurring
Advance programming
such as
Book class
librarian class
catalog
Member record class
alert
Advance programming
Each class contains various attributes and methods(Functions) which call other class attributes to
share data.
Conclusion: in this task I have define the definition about UML. For completion of task we need
to done the uml diagram of library management system which is based on scenario of Cosmos
College. So I have attach the screenshot of uml of library management system which is above.
Advance programming
Part 3
Create a lab report to show that you have implement code applying design pattern:
Evaluate the use of design patterns for the given purpose specified in M3.
Submitted To:
Submitted By:
Binod shah
Prabin Bhusal
Submitted Date:
Table of content:
Report Introduction
In the previous tasks, I had described about the UML class diagrams and presented the UML diagrams for
the library management system of Cosmos College. In this task, I will implement those class diagrams
and develop a fully functional software. Hence, I will present the screenshots of the UI designs and finally
explain about the design patterns used to develop the programs and explain about the reasons for applying
those patterns.
Screenshot of designing pattern of application building derived from UML class diagrams:
Login:
Advance programming
Dashboard:
Users form:
Advance programming
Books:
Advance programming
Members:
Issue:
Advance programming
Advance programming
Advance programming
Returns:
Advance programming
Search:
Log out:
Advance programming
Report Conclusion
While developing a web application, understanding MVC design can be an important technique since it
not only allows creating reusable and separate models which can be easily upgraded but also effectively
reduces the overall time for developing an efficient application. The MVC theory is a basic concept in
computer programming and helps in giving several web development services and projects. In this task, I
have provided implemented the Library management system for Cosmos College, and provide the
screenshots of UI and source codes to describe their implementation processes.
Advance programming
Advance programming
Part 4
Reconcile the most appropriate design pattern from a range with a series of given
scenarios.
Critically evaluate a range of design patterns against the range of given scenarios
with justification of your choices.
Article Introduction
This is the final part of our assignment that will require the description for the investigation on scenario
with respect to the design pattern. In the above tasks, I have described about the designs,
implementations, patterns and many more about the Library management system. Here, in this task, I
will describe about the range of available design patterns in the market with relevant to the examples of
creational, structural and behavioral pattern types. Furthermore, this task will also include selection of
appropriate patterns form the range with the series of given scenarios and finally evaluate a range of
design patterns against the range of given scenarios with justification for their selection and purposes.
Discuss a range of design patterns with relevant examples of creational, structural and behavioral
pattern types.
Design Patterns
Advance programming
In addition, patterns allow developers to communicate using well-known, well understood names for
software interactions. Common design patterns can be improved over time, making them more robust
than ad-hoc designs. (Sourcemaking.com, 2020)
1. Creational design patterns: These design patterns are all about class instantiation. This pattern
can be further divided into class-creation patterns and object-creational patterns. While class-
creation patterns use inheritance effectively in the instantiation process, object-creation patterns
use delegation effectively to get the job done. (Sourcemaking.com, 2020)
Here in the above code, we can see the implementation of builder pattern in a program written
with C# in Visual Studio IDE. The first picture illustrates an interface IBuilder with voids
Advance programming
BuildPartA(), BuildPartB() and BuildPartC(), which specifies methods for creating different parts
of the product objects. Then, we have created a concrete builder class that follow the builder
interface and provide specific implementations of the building steps. The concrete builders are
supposed to provide their own methods for retrieving the results since various types of builders
may create entirely different products that won’t follow the same interface. Hence, we cannot
declare such methods in statistical programming languages. Usually, after returning the end result
to the client, a builder instance is expected to be ready to start producing another product. Thus,
we call reset method at the end of the “GetProduct” method body.
It makes sense when we use the builder pattern only when the products are quite complex and
require extensive configurations. In the class product, we have created properties such as list, add
and string ListParts. The concreate builder patterns can produce the unrelated products i.e. results
various builders that maynot have same interface.
The class director is responsible for the execution of building steps in the particular sequence.
This can be helpful when we produce the products according to the specific order of
configuration. However, the director class is optional since the clients directly controls the
builders.
In the class program (where our main function runs), the client code creates a builder object,
passes it to the director and then initiates the construction process and the end result if retrieved
from the builder object.
Output:
The above figure represents output of conceptual example of builder pattern from above code
2. Structural design patterns: These design patterns are all about Class and Object composition.
Advance programming
Example Code:
The code below illustrates the adapter design pattern focusing on answering what classes consist of, their
roles and the relation of the elements in pattern exists.
Advance programming
In the above code, we create an interface named ITarget, where the target defines the domain-
specific interface used by client code. Here, we create a class Adaptee, which contains some
useful behavior, but its interface is incompatible with the existing client code. The Adaptee needs
some adaptation before the client code can use it. Now, create the adapter class that inherits the
ITarget. The adapter thus created makes the Adaptee’s interface compatible with the target’s
interface. In the main class program, when the program executes, we can see that adapter can
translate the target and give the output as shown below.
Output
Advance programming
The above picture shows the output of the given code to illustrate the adapter design pattern.
3. Behavioral design patterns: These design patterns are all about Class's objects communication.
Behavioral patterns are those patterns that are most specifically concerned with communication
between objects. (Sourcemaking.com, 2020)
Chain of responsibility: A way of passing a request between a chain of objects
Command: Encapsulate a command request as an object
Interpreter:A way to include language elements in a program
Iterator: Sequentially access the elements of a collection
Mediator: Defines simplified communication between classes
Memento: Capture and restore an object's internal state
Null Object: Designed to act as a default value of an object
Observer: A way of notifying change to a number of classes
State: Alter an object's behavior when its state changes
Strategy: Encapsulates an algorithm inside a class
Template method: Defer the exact steps of an algorithm to a subclass
Visitor: Defines a new operation to a class without change
the algorithm structure. say for an example in your project you want the behavior of the module
can be extended, such that we can make the module behave in new and different ways as the
requirements of the application change, or to meet the needs of new applications. However, No
one is allowed to make source code changes to it. it means you can add but can’t modify the
structure in those scenarios a developer can approach template design pattern.
Code example:
The code below illustrates the strategy design pattern focusing on answering what classes consist of,
their roles and the relation of the elements in pattern exists.
Advance programming
In the above code, the context class created that defines the interface of interest to clients. The
context maintains a reference to one of the strategy objects and does not know about the concrete
class of the strategy. It should work with all strategies through strategy interface. A context
accepts a strategy through the constructor, but also provides a setter to change it at runtime. The
SetStrategy function is created as the context allows replacing a strategy object at runtime. The
function DoSomeBusinessLogic represent a context which delegates some work to the strategy
object instead of implementing multiple versions of the algorithm on its own.
Then, an interface is created named IStrategy, which declares operations common to all
supported versions of some algorithms. The context uses this interface to call the algorithms
defined by the concrete strategies.
The concreate strategies ConcreateStrategyA and ConcreateStrategyB are created, which
implement the algorithm while following the base strategy interface (that makes them
interchangeable in the context).
In the main class, the client code picks a concrete strategy and passes it to the context. Here, the
client needs to know about the difference between the strategies to make the right choice. The
above code is then executed and the output is as below.
Advance programming
Output
The above picture shows the output of the given code to illustrate the strategy design pattern.
Article Conclusion
After the implementation of the application for the Cosmos College, we had to investigate the scenario
with respect to the design patterns. Hence, in this task, I had presented the range of design patterns with
relevant examples of creational, structural and behavioral patterns.
Advance programming
References: