Introduction to Object Oriented Systems Development

Object-Oriented Development uses "objects" to model real world objects. A car or a laptop can be considered as object. While traditional programming views software as a collection of functions, an object oriented system concentrates on the objects that combines data and functionality together.

The traditional approach mostly focussed on structured system development and the technique used was usually referred to as the Structured Analysis and Design Technique (SADT). 

 

Object

An object is something which has its own identity and can be easily compared to a real world object like a car or a laptop. An object contains a state and some behavior. The state of an object is the properties of the object at a particuler time, and behavior is the functions it will perform. The behaviour of an object is usually described using methods, and these methods will be part of the object itself. So you don't have to refer anywhere else for object's functionality, whereas in function based traditional approach you need to remember all the methods and their location. For instance, in java, the state of an object is the set of values of an object's variables at any particular time and the behaviour is implemented as methods. 

 

Class

Objects are grouped into a class. A class can be defined as a group of objects with the same structure and behaviour. Class can be considered as the blueprint or definition or a template for an object and describes the properties and behavior of that object, but without any actual existence. An object is a particular instance of a class which has actual existence and there can be many objects (or instances) for a class. In the case of a car or laptop, there will be a blueprint or design created first and then the actual car or laptop will be built based on that. We do not actually buy these blueprints but the actual objects. 

 

Object oriented development

In Object-Oriented Development, we apply object orientation across every system development activity such as requirement analysis, design, programming, testing, and maintenance. For instance, an object oriented analysis (OOA) will usually have the following steps:

  • Identifying the system functionality

  • Identifying the involved objects

  • Recognizing the object classes

  • Analysing the objects to fulfil the system functionality

Object-Oriented Programming (OOP) is based on object oriented features like Encapsulation, Polymorphism, Inheritance and Abstraction. These features are usually referred to as the OOPs concepts. We will see more about analysis, design, testing and maintenance later.

 

Encapsulation

Encapsulation is the process of wrapping up of data ( as properties) and behavior (as methods) of an object into a single unit (a class). Encapsulate in plain English means to enclose or be enclosed in or as if in a capsule

Encapsulation enables data hiding, hiding irrelevant information from the users of a class and exposing only the relevant details required by the user. We can expose our operations to the outside world and hide the details of what is needed to perform that operation. We can thus protect the internal state of an object by hiding its attributes from the outside world, and then exposing them through setter and getter methods. Now modifications to the object internals are only controlled through these methods.

Example from real world: Consider the smart phone you are using now. You are not worried about the internal operations of the smart phone. You only know and care about the operations or functions it exposes to you such as making call, sending SMS or using your apps.

 

Inheritance

Inheritance describes the relationship between two classes. A class can get some of its characteristics from a parent class and then add unique features of its own. For example consider a Vehicle parent class and its child class Car. Vehicle class will have all common properties and functionalities for all vehicles in common and Car will inherit those common properties from the Vehicle class and then add those properties which are specific to a car. Here, Vehicle is known as base class, parent class, or superclass. Car is known as derived class, Child class or subclass.

In multiple inheritance a class can inherit from more than one parent, but due to its complexity some languages like Java doesn't fully support it. In multi-level inheritance there will be many levels of inheritence like A inheriting from B and B inheriting from C and so on.

 

Polymorphism

Polymormism means that one operation can be used for different purposes. Poly means many and morph means form.  For instance, Java supports different kinds of polymorphism like oveloading, overriding, parametric etc. In overloading, the multiple methods having same name can appear in a class, but with different signature. Overriding is defining a method in a subclass with the same name and type signature as a method in its superclass and the overriden method is called at runtime based on the object at runtime. 

 

Abstraction

In plain English, abstract means a concept or idea not associated with any specific instance and does not have a concrete existence. Abstraction in OOP emphasizes what is important and what is not important at a particular level of detail. Abstraction refers to the ability to make a class abstract at a level and define some of the behaviour at each level, relevant to the current perspective. Abstraction allows the programmer to focus on few concepts at a time. Java provides interfaces and abstract classes for describing abstract types. 

 

Coupling vs Cohesion

Coupling and cohesion are two important concepts in the Object Oriented design and hence we will briefly discuss it here.

Coupling is the degree to which one class knows about another class. If the knowledge is only through exposed interfaces (data hiding), it is called loosely coupled. If the knowledge is more like accessing data members directly, it is called tightly coupled. We should try to make our code as loosely coupled as possible. Even though you make some change in a class adhering strictly to the class's API, tight coupling can make other classes that use this class not working properly after the change.

The term cohesion is used to indicate the degree to which a class has a single, well-focused purpose. The more focused a class is, the higher its cohesiveness, which is a good thing. The key benefit of high cohesion is that such classes are typically much easier to maintain than classes with low cohesion. Another benefit of high cohesion is that classes with a well-focused purpose tend to be more reusable than other classes.

In summary, loose coupling and high cohesion are desirable, whereas tight coupling and less cohesion can lead you to problems in the long run.

 

Advantages of object oriented software development

Some of the advantages of object oriented software development are:

  • Less maintenance cost mostly because it is modular.

  • Better code reusability due to features such as inheritance and hence faster development.

  • Improved code reliability and flexibility

  • Easy to understand due to realworld modelling.

  • Better abstraction at object level.

  • Reduced complexity during the transitions from one development phase to another.

Comments

Hi Heartin,

I am a Beginner in java. I have doubt on the following,

why  we use getters and setters, it has the same use of making the properties public?

 

Thanks in advance,

Chinnu

Was it useful?

Good question and you are somewhat correct. Efectively it has the effect of making the variable public and few even consider it as non-object oriented. 

But in certain cases, it does make sense, like to have some kind of extra validation for the data before setting or even having a an additional logic for getting data.

Consider a linked list. Imaging that you have a size variable and people are directly accessing it to get size. But later you decide to change the logic to calculate the size every time someone ask for it rather than storing it in a variable. With direct access to the variable, you can never do this without changing client code; but if they were using a getSize() method, they could easily change "return size;" with your new logic and the client code will never need to be changed. 

Was it useful?

Thanks Heartin..now it is clear for me

Was it useful?

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)