Object oriented concept

Have been kept this post in draft for quite some times. Not sure when I'll start with my next topic. So, I decided to post this first.

Here's the first chapter, object oriented concept.

Let’s go through an example before explore the object oriented jargons.

Say, there is a book shelf. We have some books, a pen holder, pens, pencils, sharpener in the book shelf as illustrated below.



These objects are related to each other in some ways. The bookshelf contains books, pens, pencils, pen holder and sharpener. The sharpener is used to sharpen the pencil. The pen holder holds the pens and pencils. There is variety of books in the bookshelf.

How is this related to object oriented concept?

Class

A class is a collection of objects that has something in common. Say, we have a class of book. All books are classified in the class of book.

Object

Object is something real that exists. It is classified with other objects that share some common attributes into class. We can have Mind Maps by Tony Buzan as an object of book. We can have Harry Potter and the Order of the Phoenix by J.K Rowling as an object of book. We can also have exercise books and dictionaries as objects of book.

There are 2 types of relationship here. Is-a (inheritance), the Mind Maps is a book. Has-a (composition), the pen holder has a pencil in it.

Information hiding (encapsulation)

Let’s take the sharpener as example here. You know the function of this object is to sharpen a pencil. You put in a pencil, apply forces and turn the side handle, after a while, you’ll have the pencil with a pointed end. The side handle and the hole that hold the pencil are interfaces that we could reach. How exactly it works within the sharpener, doesn’t really matter to us. Besides, it also helped to safe guard, that the blade in the sharpeners will not hurt us. And we need not to know how many blades in the sharpener to do the function. This is what we called information hiding.

Inheritance

Inheritance is a concept in object oriented design that helps in classified the objects. Book is a big class. We can have dictionary, exercise book, fiction and non-fiction book to be categorized under this general class, book. We classified each object based on the common attributes. We can further classify based on other shared attributes. As illustrated in the diagram below, all books have number of pages as its common attribute. Dictionary would hold the number of word entry where the exercise books or fiction books doesn’t share this attribute. However, these 3 classes (dictionary, exercise book and fiction book) share the same attributes in the book class. Thus, they can exist as sub-class of book, and inherit the attribute from the book class.



Polymorphism

Let’s say we want to write something on an exercise book. We can use a ballpoint pen, a pencil, a fountain pen, a charcoal pencil to write. Polymorphism is a concept that allows the replaceable objects to do the same thing.

This passage is focusing on object oriented concept in using SystemVerilog. There are more jargons for software engineering which are not discussed here.

Jaa, till next.

Comments

Popular Posts