Design Principle vs.Design Pattern: Describing OOP elements

In This article:

  • You will able to learn basic elements of a Object Oriented Design.
  • You will able differentiate design pattern and design principle.
  • At the end you will get some useful links and books to read.
  • Finally you will bag at least one more interview question and their clarification.

The Background:

  • Why these definitions and descriptions needed-

Most of the time developers have to work on enhancements based projects, where they have to understand the code which is already written by some other people.  The understanding of code base takes time based on project architecture. Then during analysis of code a query always tickles, in one corner of the mind of the developers, “why-this-extra-class-needed” or some other similar lines.  This type of queries came in mind when one is not aware of the paradigm used and patterns. There are several books and sites you will find on this but here you will get the base of a good design. This is not so fancy, but if you will burn it in your mind- your understanding will be much deeper.

Explore this:

Elements of OOP

Elements of OOP

OOP—

  • Stands for Object Oriented Programming.
  • Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects” that have data fields (attributes that describe the object) and associated procedures known as methods. Objects, which are instances of classes, are used to interact with one another to design applications and computer programs.
  • OO basics are-
  1. Abstraction
  2. Encapsulation
  3. Polymorphism
  4. Inheritance
  • Please avoid writing it as OOPs or OOPS. Please see this article.

OO Design Principle—

  • OO principle is a set of guidelines that ensures OOP concept.
  • Based on the OOP concept, this defines ways to design better way, a better design.
  • The basic OO design principle is SOLID.
  • SOLID is known as-
  1. Single Responsibility Principle

         A class should have only one reason to change.

     2. Open Close Principle

        Software entities like classes, modules and functions should be open for extension but closed for modifications.

     3. Liskov’s Substitution Principle

         Derived types must be completely substitutable for their base types.

     4. Interface Segregation Principle

         Clients should not be forced to depend upon interfaces that they don’t use.

     5. Dependency Inversion Principle

        High-level modules should not depend on low-level modules. Both should depend on abstractions.

        Abstractions should not depend on details. Details should depend on abstractions.

OO Design Pattern-

  • A Design pattern provides a general solution to a design problem.
  • Please note “design pattern” can be applied to noon object oriented word too. So A OO design patterns (OODPs) are those which provide a general solution to object oriented design based OO principle.
  • Design patterns are discovered, not invented.
  • There are several ways to define OODPs and most famous one is BSC [Behavioral Structural Creational].
  • Understanding BSC-
    • To create objects one need of classes. This is start of design.
    • A class must have well defined attributes. The design solution made to compose class structure is known as Structural patterns.
    • Now you have class, to create objects one needs to create object(s). The design solution made to instantiate a class or classes is known as Creational patterns.
    • Once object instantiated, think of objects interactions. So those design solutions which are concerned with object interactions are known as Behavioral patterns.

Best Practices-

  • Best practices can be used in OODPs to avoid business errors or run time errors.
  • There can be multiple techniques to do some tasks but to do in efficient and effective way can be said Best practices.
  • Example-

In java there are multiple ways to iterate a map, but if you want to get just list of keys do not use iterator or entryset, but use keyset.

Type safety can be another example of best practices.

Summary-

So by understanding above definitions we can conclude that design patterns uses to implement an OO design problem. These patterns use OO Principles and Best practices to ensure OO paradigm with highly scalable and efficient design.

What Next:

Just start with basics principles and design. If you don’t know which way to go, then follow the links and books given in useful link. Don’t just dive in technologies; first grasp the basics of all these technologies.

Useful Link:

  • Notes on basic design principle and pattern-
  1. http://www.oodesign.com/
  2. http://hillside.net/
  • Some more design principle can be found at this site
  • The best book to start with design pattern is-
  1. Head First Design Patterns.
  2. Amazon Link
  3. Flipkart link

Print this article:

Happy Reading,

Nirbhaya Bhava!!!

OOPS vs. OOP – What “s” stands for?

In this article:

  • Explores the meaning of OOP and OOPS.
  • At the end of this article you will be able to differentiate OOPS and OOP.
  • This may be part of your interview question on Design pattern.

The background:

This is most common misunderstood short form related to object oriented paradigm. If somebody asks which paradigm you use or on which paradigm Java works. We generally answer it as OOPS or OOPs. And here we do mistake. Also this came as a conundrum when interviewer asked to my buddy what “s” stands for.

Explore This:

First grab the full form, then I will explain it further—

Differentiate OOPS and OOP

Differentiate OOPS and OOP

Oops!! Yes. This is the sound you must whisper. Well OOP you already know, following is the definition of OOPS (actually oops – not in CAPS)

Definition of oops

Yes this is official definition of oops.

What Next:

So next time, to break the awkward silence between you and another developer, you have got a nice    topic to break the ice.

Printable Doc:

OOPS vs OOP

Happy Readings,

Nirbhaya Bhava!!!

Spring – The Context: ApplicationContext vs. BeanFactory

This article describes the difference between ApplicationContext and BeanFactory in Spring framework.

- BeanFactory is recommended for lightweight framework like — Mobile and Applet.

- BeanFactory is core component of Spring IoC container.

- As ApplicationContext extends BeanFactory so ApplicationContext is more powerful than BeanFactory (like AOP, Internationalization etc.)

con1

-          You can configure your beans in the Spring IoC container through XML files, properties files, annotations, or even APIs.

-          Container reads these beans by using BeanFactory (or ApplicationContext)

-          Let’s say you define the beans in XML file, say applicationcontext.xml.

-          Now BeanFactory has to read applicationcontext.xml to load the beans in container.

-          For this BeanFactory needs an interface that can provide the xml file o BeanFactory.

-          This interface called resource object.

-          Sample:

context3

-          In case of ApplicationContext, the resource object is implemented internally, so as use We don’t  need of resource object.

context4

cntext2

Hope this will clarify the basic difference.

Happy Reading,

Nirbhaya Bhava!!

Spring Series: Spring JDBC – Review/Interview Questions

Image

Following is the list of useful questions and hints for recalling support provided by spring for JDBC. Please note, these basically cover Spring 2.5 version, few of them may applicable to higher version. –

  1. What are the core packages provided by Spring to work with JDBC?
  2. What is the difference between SimpleJDBCTemplate and NamedParamJDBCTemplate?
  3. How one can translate the exception using Spring JDBC classes?
  4. What are the essential callback interfaces to be implemented, to use JDBC Template?
  5. Where is Collections.singletonMap(…) method used and why?
  6. Where does one use ParameterizedRowMapper?
  7. When do one uses executeAndReturnKey method and where is it define?
  8. How to insert data into a table, where table is having five columns but you have to insert data just in three columns (obviously the rest two columns allows null values)?
  9. What is the better way to insert values in table, if the values are provided in the form of java bean instance?
  10. How MapSQLParameterSource is different from BeanPropertySQLParameter?
  11. How to call procedure using Spring?
  12. How to ensure case insensitive look-up for parameters name when calling procedure?
  13. What is the way to avoid metadata look-up from spring controller when calling procedure?
  14. How to call database functions in spring?

Hint:

  1. [CDOS in short] core, datasource, object, support.
  2. SimpleJDBCTemplate takes advantages of java 5 features – varargs, autoboxing.
  3. Using “support” package classes.
  4. PreparedStatementCreator, CallableStatementCreator, RowCallbackHandler.
  5. One example is when one uses NamedParameterJdbcTemplate, singletonmap used to provide value of parameter.
  6. When code selects data from database using SimpleJdbcTemplate class.
  7. If developer needs to implement auto generated keys.
  8. Either use usingColumns(…) method or MapSQLParameterSource.
  9. By using BeanPropertySQLParameterSource.
  10. BeanPropertySQLParameterSource uses java bean instance (value object) to store data while MapSQLParameterSource uses addValue method to set values of columns.
  11. Using withProcedureName(String name_of_procedue) provided in SimpleJdbcCall class.
  12. By setting new JdbcTemplate(datasource).setResultsMapCaseInsensitive(true).
  13. By calling SimpleJdbcCall(new JdbcTemplate(datasource)).withProcedureName(name_of_procedure).withoutProcedureColumnMetadataAccess();
  14. withFunctionName(name_of_function).

Happy Reading,

Nirbhaya Bhava!!

Code Build: Shortcut to open code location

Most of the time to fix a problem, dev people try to build the updated code. Since the update made was in just few classes so its really bad to provide full build on dev environment. So its better to ask for patch of class files. So people generally browse the location through windows or command by pasting the location. Stop doing that. Windows provide shortcut cuts, from command prompt itself.

Just type one of the following-

  1. explorer.exe .
  2. start .

These command will open the location of source file, from there its easy to navigate towards class files.

This is not a wow factor, but a way to simplify the hectic dev life..

Enjoy applying,

Nirbhaya Bhava!!

Oracle – SQL: Find table(s) having a particular column

Some time to solve problems, we need to check database, but unluckily we don’t the exact table name and/or column to look for.

Following are the handy queries which solves out these problems—

  • When you just know few words of table name, then below query list down all the tables having similar name-

SELECT * FROM TAB WHERE TNAME LIKE ‘%few_parts_of_name%’;

  • Some times from application code we can guess the table name but not able to find out exact table name. Following query shows how to list down all the tables having a column name –

SELECT table_name, column_name

FROM all_tab_columns

WHERE column_name LIKE '%PUT_HERE_COLUMN_NAME%'

ORDER BY table_name, column_name;

This query show all the tables and/or views having column name like <PUT_HERE_COLUMN_NAME

> in all the available schema.

If you are sure about the schema, following flavor will narrow down the result—


SELECT owner, table_name, column_name

FROM dba_tab_columns

WHERE column_name like '%PUT_HERE_COLUMN_NAME%'

and owner='APPS'

ORDER by table_name;

Additionally, you can use TABLE_NAME in where clause inside both queries to narrow down the result.

Keep this handy; it’s kind of utility queries which are always helpful.

Happy Reading,

Nirbhaya Bhava!!!

Just One Step before Production Deployment: Whether which-logger-level-enabled matters on non-production environment?

This month, we as a team implemented the requirements as decided during sprint planning.

Actually, our project works on AGILE methodologies, where each release is scheduled after 4 weeks.

So in this lesser time, fulfill the client demand is quite tuff. Sometime it’s too hectic.

Anyways, as a standard process, before closing the release lifecycle, we execute the migration doc (this contains all the property file changes, script, the build number etc.),

on production clone environment, and if needed we go for LT (load testing).

During the current release, when QA team was about give sign-off on QA environment, we found issue on our one of the application.

This was deployed on production clone environment. User was not able to log-in the application. Even no errors were in log (what the heck? Eh!!!)

All developer started debug the problem and time was passing like anything (whenever we IT people get severe problem, each second passes, feels like an hour gone. Isn’t it?)

Suddenly, The GOD opened our door. We identified, that yesterday somebody updated files with missing isInfoEnabled statements.

“If that is so, if we modify the log level will resolve the problem for the time being”, one of the team member thought.

So, we followed our man of thought, modified the log level- from ERROR to DEBUG.

And, luckily we were able to log-in to application. Hurray!!

Next step was to identify such piece of code and we corrected.

But what we learned from this? What if it was caught on production?

Obviously, there could be escalations. Only having exact database and running migration doc properly may insure the correctness of release going on,

But what about the configuration of log file? It really matters. From that incident onwards, we made it standard to keep everything like production environment, before giving sign-off, especially on QA environment.

We can try our level best to make life easy but standardizing such processes, which can be learned from experience. Please share if you have faced any such issue, as sharing can spread smiles.

Happy Reading..

Follow

Get every new post delivered to your Inbox.