.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 












Saturday, September 28, 2019

Lesson O1 - Angular 7



Structure Directives (ngIf  , ngFor , ngSwitch)


ඔයාලා මිට පෙර if else, switch case , for loop මෙන්න මේ වගෙ දෙවල් ටිකක් ගැන  C language  හො java වැනි language වලින් ඉගෙන ගෙන තියනව නම් ඔයාලට මතක ඇති  කියලා මන් හිතනවා. අන්න ඒ  වැඩ ටික කරගන්න තමයි angular වලදි මෙන්න මේ Structural Directives use වෙන්නෙ.


1)   අපි  බලමු ngIf Directive කියන්නෙ මොකද්ද කියලා.


මේකෙදි වෙන්නෙ සරල වැඩක් මොකක්  හරි variable එකක් true උනොත් මේ ngif එක යටතේ තියෙන දෙවල්  වැඩ කරනවා . එහෙම උනේ නැත්නම් ඒ කියන්නෙ false නම් වැඩ කරන්නෙ නෑ . පහත  නිදසුන බැලුවොත් ඔයාලට ඒක පැහැදිලි වේවි.


component.ts
component.html

ඔයාලට පහත ආකරයෙ output එකක් බලාගන්න පුලුවන් වෙවි.



මේක පහත ආකාරයට else part  එකක් add කර  ගන්න පුලුවන්.එකට ng-templete කියලා elements එක්ක හදා ගන්න වෙනවා.එහෙම  එක්ක හදා ගෙන ඒකට පහත ආකරයට reference variable assign කරගන්න ඕන.

component.ts

component.html


දැන් අපිට බල ගන්න පුලුවන්  true block එක වැඩ කරලා "Condition is true" කියල output එකක්. මොකද අපි ts file ඒකෙ "condition=true;" කරලා තියන නිසා.




දැන් අපි බලමු ngIf Directive වල special අවස්ථා ටිකක්.


1.1)  කොහොමද string value එකක් compare කරන්නෙ  කියලා.

component.ts

component.html

ඒකෙදි ඔයාලට බල ගන්න පුලුවන් වෙයි පහත ආකාරයෙ  output එකක්.



1.2) කොහොමද integer value එකක් compare කරන්නෙ  කියලා.

component.html

component.ts

ඒකෙදි ඔයාලට  පහත output එකක් බලා ගන්න පුලුවන් වෙවි.



ඉහත ආකාරයටම AND ,OR  Operations වලටත් ඔයාලා කරල බලන්න.

වැඩි විස්තර බලා ගන්න ඕනනමි පහත Link එක Click කරන්න.

https://angular.io/api/common/NgIf



2 )   දැන් බලමු ngFor Directive කියන්නෙ මොක්කද? කොහොමද                  එකෙන් වැඩ කරන්නෙ  කියලා.


for කියද්දි අපට මතක් වෙන්නෙ looping . මේ ngFor Directive එක use වෙන්නෙත් loop වලට . ඒ කියන්නෙ template  එකේ එකම component එකක් හරි form එකක් හරි කිහිපවතාවක් පෙන්නගන්න ඕන නම් . ඒ කියන්නෙ array එකක තියෙන elements ටික පෙන්නගන්න ඕන කියලා හිතන්න. මේ වගේ වැඩ වලට තමයි ngFor use කරන්නෙ .

දැන් මම පහත ආකාරයට array  එකක් හදා ගන්න ඕන.

  name=['Madhusanka','Edirimanna','Pramodi','Samaratunga'];

දැන් අපි මේක template එකේ එකින් එක පෙන්න ගන්නේ කොහොමද කියල බලමු .ඒකට මෙන්න මේ වගෙ syntax එකක් use වෙනවා.*ngFor='let myName of name';

මෙකෙන් කියවෙන්නෙ name කියන array එකෙන් එක බැගින් අරගෙන myName කියන variable එකට assign කරන්න කියන එක.මෙතන myName වෙනුවට අපට කැමති නමක් දෙන්න පුලුවන් . නමුත් name කියන එක වෙනස් කරන්න බෑ . ඒක තමයි array එකේ name(නම) එක.

දැන් ඉතින් Myname කියන variable එක view කරගන්න තියෙන්නෙ...ඒකට interpolation use කරන්න පුලුවන්.මතක ඇති component එකේ තියෙන දෙයක් template එකේ පෙන්නගන්න interpolation යොදා ගන්න ඕන. double curly brases දාගෙන.ඒකම තමයි මෙතනත් කරන්න තියෙන්නෙ .

component.html

component.ts
 මේක පහත විදියට view කරලා බලාගන්න පුලුවන් .


පහත ආකරයට  තමන්ට කැමති element විතරක් array එකෙන් view කර ගන්න පුලුවන්.ඒ සදහා පහත syntax භාවිතා කරන්න පුලුවන්.

component.html

component.ts

වැඩි විස්තර බලා ගන්න ඕනනමි පහත Link එක Click කරන්න.

https://coryrylan.com/blog/angular-ng-for-syntax


03 )   දැන් බලමු ngSwitch Directive කියන්නෙ මොක්කද? කොහොමද             එකෙන් වැඩ කරන්නෙ  කියලා.

java වල switchcase තේරුනා නම් මේකත් ඒ වගේමයි.හරිම ලේසියි.සමාන output කිහිපයක් තියෙද්දි  නිවැරදි එක තෝරගන්න තමා මේක use කරන්නෙ.java වල වගේම ngSwitch කියල මුලින්ම අදාල variable එක assign කරනවා . ඊට පස්සෙ *ngSwitchCase කියල selective ටික assign කරනව .  code එක බැලුවාම හොදටම පැහැදිලි වේවි ඔයාලට.



component.html

component.ts




වැඩි විස්තර බලා ගන්න ඕනනමි පහත Link එක Click කරන්න.

https://angular.io/api/common/NgSwitch


අපි එහෙනම්  next lesson එකෙන් හමුවෙමු.

By :- Madhusanka Edirimanna


Saturday, July 13, 2019

Introduction to Japanese for Beginners......

As a beginner to japanese language you may know that there are three type of letter in japanese language.


  1. Hiragana
  2. Katakana
  3. Kanji

To learn the language easily and quickly you should follow the above order of three type of letters.


Hiragana


Hiragana  letters usually have  phonetic sounds.These are basically used for particles, words and part of words. This express 46 different sounds used in the japanese language.when practising hiragana letters you will be able to pronouns japanese letters properly,read and write.If you learn hiragana first it will be easier to learn katakana next.


Katakana

These letters are basically used for foreign words.Katakana is a phonetic alphabet.Katakana was developed in the 8th century by simplifying the form of kanji symbols. Katakana and Hiragana represent exactly the same set of sounds.




Kanji


These are chinese characters and used for the stem of words and convey the japanese language.



********
As a beginner you should learn how to write and pronounce vowel letters in hiragana alphabet.




 Above letters are in the order of English Vowels A, I , U , E, O.

After practising vowel sounds in hiragana alphabet you should try following letters.




  • Try the following exercise after practising above letters.
  1. aka (red)
  2. ao (blue)
  3. aki (autumn)
  4. ie (house)
  5. koe (voice)
  6. kao (face)
  7. ue (on top)
  8. kaki (permission)
  9. eki (station)
  10. okii (big)



By : Pramodi Samaratunga  - University Of Moratuwa 

        Madhusanka Edirimanna - University Of Moratuwa 


       

 





Friday, July 12, 2019

B+ Tree...

Examples for Insertion of data in to a B+ Tree


B+ tree is a rooted tree that consist of a root,internal nodes and leaves.In a B+ tree of order ( or branching factor) n should satisfy the following properties.

  • From root to leaf all the path's length should be same.
  • Each node that is not a root or a leaf has between (n/2) and n children. 
  • A leaf node has between ((n-1)/2) and n-1 values. 
  • If the root is not a leaf it has at least 2 children .
  • If the root is a leaf (there are no other nodes in the tree) it can have and 0 and (n-1) values.


Example 01-Enter numbers in to a B+ Tree

Branching factor-5
Number Sequence-5,10,15,20,25,30,35,40,50,55,65,70,75,80,90,95


Not a root or leaf has children between = (n/2) , n
                                                                  
                                                                   =(5/2), 5
             
                                                                   = 3,5

Leaf node has values between                =((n-1)/2) , (n-1)

                                                                  =(4/2), 4

                                                                  =2,4 










Example 02-Enter Strings to a B+ Tree

When you entering strings to a B+ tree you should consider the alphabetical order.

Branching factor=3

Colombo,Kandy,Galle,Badulla,Gampaha,Kottawa,Kalutara


Not a root or leaf has children between = (n/2) , n

                                                                   = 2, 3

Leaf node has values between                =((n-1)/2) , (n-1)

                                                                   = 1 , 2







Advantages of B+ Tree


  • Insertion, Deletion, Update does not affect to the performance since it is a balance tree structure.
  • Searching data is becomes more easy since all records are stored only in the leaf node.
  • Minimizing disk accesses by lowering the tree height due to large node fanout.
  • Keys are used for Indexing.

Disadvantages of B+ Tree


  • This method is less efficient for static tables.




By : Pramodi Samaratunga      -  University Of Moratuwa 

       Madhusanka Edirimanna  -  University Of Moratuwa 

SPRING MVC SIMPLE CRUD APPLICATION