.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; } .code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }

Wednesday, March 25, 2020

Software Design Patterns



Design Pattern 

“Each pattern describe a problem which occurs over and over again in our environment, and then describe the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice”
 [Christopher Alexander]

Design Pattern Space

There are two criteria of  design patterns namely Purpose and the Scope.

Purpose - What pattern does

Mainly there are 23 design patterns which categories under three main categories. Those are Creational , Structural, and Behavioral patterns.
  • Creational – Process of Object creation 
  • Structural – Composition of Classes or Objects
  • Behavioral – Classes or Objects interact and distribute responsibility 
Scope - Whether the pattern applied primarily to a class or an object
  • Class – Deals with relationships between classes and sub-classes (Via inheritance and static) 
  • Object – Deals with object relationships (can be changed at runtime and dynamic)
Advantages of Design Patterns
  • Can reusable in multiple projects.
  • They capture the software engineering experience.
  • They provide transparency to the design of an application
  • They are well-proved and testified solutions since they have been built upon the knowledge and experience of expert software developers
  • These do not guarantee an absolute solutions.


Singleton Design Patterns

Singleton design pattern is one of the simplest design pattern and this categories under creational design pattern. this class have a single class which  create only one object.

Examples for singleton are
  • Clip Board
  • Windows Registry

Step 1 - Create a Singleton class

SingleObject.java


Step 2 - Get the only object from the singleton class

SingletonPatternDemo.java


Step 3 - Verify the Output




Written by - Pramodi Samaratunga
                     Madhusanka Edirimanna
Undergraduates - University of Moratuwa


Software Architectures


Enterprise Architecture is about understanding all of the different elements that go to make up the enterprise and how those elements interrelate

 -[The Open Group]-

Without Architecture

  • Unpredictable Solutions
  • Poor quality and reduced user experience
  • Stunted evolution
  • Rigid system - Hard to reuse 

There are many types of software architectures.

  • Layered Architecture
  • MVC Architecture
  • Component Based Architecture
  • Service Oriented Architecture
  • Enterprise Architecture

In this article we only discus about the layered architecture and MVC architecture.

Layered Architecture

One of the most common architecture pattern is layered architecture that stand for most Java EE applications. Most of the time layered content four major layers namely presentation, business, persistence and database. But it is not specify special number of layers. These layers are organized as horizontal layers. In small applications there are only 3 layers and in complex application there are five or more layers. In an component it does not worry about other components’ logic.


Presentation layer – Responsible for handle the browser communication logic and user interfaces.

Business layer- According to the request this layer execute specific business logics.

Persistence layer – Contain the classes that responsible for technical stuffs.

Database – Represent data in the application and provide an interface to a database.

Fig.1.Layered Architecture


Applications of layered Architecture

  •          World wide web
  •         Web application development
  •          Mobile application development

Advantages

  •          Developer can work pararllelly in the application.
  •          Increase the scalability, maintainability, and flexibility.
  •          Have different levels of security.
  •          Each component can work independently.
  •          Can reuse the components by multiple applications.

Disadvantages

  •          Add complexity to small applications. Not suitable for small applications.
  •          Can decrease the performance because the data passing through components instead of directly call     for the components.
  •          Sometimes difficult to decide the number of layers.
  •          Chance of various improper stability issues if not handled correctly.

    MVC Architecture

MVC architecture is mostly use software architecture to develop applications. MVC stand for Model, View, Controller.

Model – All the logic related data that user work with is handle by Model. This can represent the data that transfer between the View and the Controller Components. This is like the database in your application.

View – All the UI applications that customer finally interact with are include in this component

Controller – This is act as an interface between Model and View. This process all the business logics.


Fig.2.MVC Architecture

Applications of MVC Architecture

  • Development of mobile application
  • This is first desktop application and now mostly use in web applications.

Advantages

  •         Can create multiple Views of a Model.
  •          Multiple users can access an do the development process. One can work in View while         other work with Controller. So the process is faster.
  •         Support asynchronous techniques.
  •         Can use for develop large web applications.
  •         For the return of data, no need of formatting.
  •          If we do a modification in a component it does not affect to whole architecture.

Disadvantages

  •          Not suitable for small applications.
  •         The complexity is high when develop applications.
  •         Increase the cost because of frequent updates.
  •         Required knowledge of multiple technologies.
  •         Multiple developers need for parallel development.



Written by : Pramodi Samarathunga
                    Madhusanka Edirimanna
 Undergraduates - University of Moratuwa 












SPRING MVC SIMPLE CRUD APPLICATION