Application Programming Concepts

13 October 2017

Programming is a process that leads from an original formulation of a computing problem to executable computer programs. Programming involves activities such as analysis, developing understanding, generating algorithms, verification of requirements of algorithms including their correctness and resources consumption, and implementation.

Pillars of Object Oriented Design

There are four pillars in object oriented design

  • Abstraction
  • Polymorphism
  • Inheritance
  • Encapsulation

Collectively they are knows as APIE.

Abstraction: It is used to hide internal details and only expose functionality of code. In Java, abstract class and interface are used to achieve abstraction

Polymorphism: It is a standard OO principle whereby one or more “sibling” classes may be defined as being children of some parent class, and where these classes provide some different implementations for the same method(s).

When one task is performed by different ways. In Java, we use method overloading and method overriding to achieve polymorphism.

Inheritance: When one object acquires all the properties and behaviours of parent object and provides code reusability it is known as polymorphism.

Encapsulation: Encapsulation is the ability to package data and related behavior into a single unit and hide them from external elements. When we say encapsulation, emphasis should be on grouping or packaging or bundling related data and behavior together.A Java class is the example of encapsulation.

Classes ,Object ,Field and Methods

Class: A class is an object-oriented programming concept.A class is a template or blueprint for creating objects at runtime.Class is a logical entity which is a collection of objects.

Object: An object is an instance of a class. It is an entity that has state and behavior. It can be physical and logical.

A class is defined in source code, whereas an object exists at runtime.Class consists of fields and methods.

Field: A field is a variable, which is used to store data.

Method: A method contains executable code. It is a function defined inside a class. A method has access to all the fields of a class.

SOLID principles

The term SOLID in computer science refers to 5 design principles which intends to make software designs more understandable ,flexible and maintainable.

  • Single Responsibility Principle
  • Open/closed Principle
  • Liskov substitution principle
  • Interface segregation principle
  • Dependency Inversion Principle

Singleton pattern

In the field of Software engineering ,the singleton design pattern is a software design pattern that restricts the instantiation of a class to one object .It is mainly useful when one object of an application needs to interact with all the other systems .

To implement this pattern we need to

  • ensure that only one instance of Singleton class exists on the same JVM
  • ensure that singleton provides global access to that instance

To do this we need to

  • declare all constructors of the class to be private
  • provide a static method that returns a reference to the instance of singleton object

Example: Lazy Initialization of Singleton

public final class SingletonExample {

private static volatile SingletonExample instace = null;

//Private Constructor
private SingletonExample() {}

//Static Method
public SingletonExample getInstance() {

if (instance == null){
  synchronized(SingletonExample.class){
  if(instance == null){
      instance = new SingletonExample();
  }
  }
}
}
}

Web Service

Web service is a way of communication that allows interoperability between different applications on different platforms. For example, a Java based application on Windows can communicate with a .NET based one on Linux. The communication can be done through a set of message format like XML or JSON.

Web services are browsers and operating system independent service, which means it can run on any browser without the need of making any changes. Web Services take Web-applications to the Next Level. It is based on technologies such as HTTP, XML, SOAP, WSDL, SPARQL, and others.”

Multithreading vs MultiProcessing

In Python programming language multithreading module uses thread whereas multiprocessing module uses processses.Main difference between them is that threads share the same memory space whereas processes have seperate memory .Because of this ,it is difficult to share object between processes when developing multiprocessing applications . As threads share the same memory ,developers will have to careful while using the same memory at same time.

DAO vs DTO Layer

  • DTO(Data Transfer Objects) Layer It is used to transfer the data between classes and modules of an application. When application has remote interface each calls is expensive .When dealing with application where we need to transfer data ,we need to reduce the number of remote calls. To reduce the call we use DTO which holds all the data for the call .It needs to be serializable to go across the connection .It contains private fields of the data with getters, setters and constructors.

  • DAO (Data Access Object) Layer

It abstracts and encapsulates all access to the data source. It encapsulates the logic for retrieving ,saving and updating data in the data storage like a database ,a file based system .

It implements the access mechanism required to work with a data source. In an application , data source could be a persistant database system like RDBMS,file base system or a business service accessed by REST or SOAP.

Factory in OOP

In object-oriented programming (OOP) ,factory is a function or method that returns objects of a varying prototype or class from some method call, which is assumed to be “new”.

Stateful vs Stateless

  • Stateless Programming

Stateless means there is no memory of the past. Every transaction is performed as if it were being done for the very first time.

There are lots of advantages to stateless programming, not least of which is dramatically multithreaded and concurrent code. To put it bluntly, mutable state is enemy of multithreaded code. If values are immutable by default, programmers don’t need to worry about one thread mutating the value of shared state between two threads, so it eliminates a whole class of multithreading bugs related to race conditions. Since there are no race conditions, there’s no reason to use locks either, so immutability eliminates another whole class of bugs related to deadlocks as well.

  • Stateful Programming

Stateful means that there is memory of the past. Previous transactions are remembered and may affect the current transaction.

When an application operates in a stateful mode, the server keeps track of who users are and what they do from one screen to the next. Preserving the state of users’ actions is fundamental to having a meaningful, continuous session. It typically begins with a login with user ID and password, establishing a beginning state to the session. As a user navigates through the site, the state may change. The server maintains the state of the user’s information throughout the session until logout

Log Levels in Application

There are different log levels available in Java Applications.

Log Level Descriptions
DEBUG Provides fine-grained informational events that are most useful to debug an application.
ERROR Gives error events that might still allow the application to continue running.
FATAL very severe error events that will presumably lead the application to abort or crash.
INFO Contains informational messages that is logged in the applicaion.
OFF The highest possible rank and is intended to turn off logging.
TRACE Gives finer-grained informational events than the DEBUG.
WARN Gives information about harmful situations in applications.

References

[1] Abstract class vs Interface

[2] DAO and DTO

Share: Twitter Facebook Google+ LinkedIn
comments powered by Disqus