Author Archives: proctech21

Interface

Abstraction is the most essential piece of object-oriented design. It allows the client peace of mind when it comes to the implementation details of functionality. In Java, abstraction is achieved through abstract classes and interfaces. This post will find the idea of the Interface Segregation Principle.

An Interface is a set of abstractions that an implementing class must follow. We define the behavior but don’t implement it:
in the example below, we will find how that is being written.
interface Car {
void break();
}
Using the interface as a template that actually can help us to implement the behavior:
class Toyota implements Car {
public void break(){
// Toyota-specific implementation
}
}
What Is the Interface Segregation Principle?
The Interface Segregation Principle (ISP) states that a client should not be exposed to methods it doesn’t need. Declaring methods in an interface that the client doesn’t need is problematic for several reasons.
Let’s look at an example to understand why the Interface Segregation Principle is helpful.
By creating these codes below you will be able to analyze how the methods are being called. Let’s formed an order service place where a customer can order an oil change, change tires, or basic tuneup:

interface OrderService {
void oilchange(int quantity);
void tirerotation(string front, string back);
void basictuneup(int quantity, string front, string back);
}

Since a customer has the opportunity to order an oil change, or tire rotation, or both, it will make sense to put all order methods in a single interface which be seen in the codes below.

class OilchangeOrderService implements OrderService {
@Override
public void oil-change(int quantity) {
System.out.println(“Received order of “+quantity+” oil change”);
}

@Override
public void ordertireroation(string front, string back) {
throw new UnsupportedOperationException(“No tirerotation in oil change only order”);
}

@Override
public void ordertuneup(int quantity, string tireration) {
throw new UnsupportedOperationException(“No tirerotation in oilchange only order”);
}
}
Similarly, for a tirerotation-only order, we’d also need to throw an exception in orderOilchange() method.
And this is not the only downside of this design. The OilchangeOrderService and TirerotationOrderService classes will also have unwanted side effects whenever we make changes to our abstraction.

This change will also affect oilchangeOrderService even though it’s not implementing this method!
By violating the ISP, we face the following problems in our code:
• Client developers are confused by the methods they don’t need.
• Maintenance becomes harder because of side effects: a change in an interface forces us to change classes that don’t implement the interface.

From the blog CS@Worcester – Site Title by proctech21 and used with permission of the author. All other rights reserved by the author.

Object-Oriented Programming(OOP)

This week’s blog focuses on the aspects of object-oriented programming. Understanding OOP well is essential for any developer who wants to build a high-quality software program.

In object-oriented programming, the program will be divided into many different small, manageable, reusable programs.

Each of them has its own identity, data, logic, and how it’s going to fit with the rest of the others. Usually, we may think about objects, we think about the real-world application. Something we should be able to see, touch, and feel. Then Object-Orientation was intended to be closer to the real world.

As mentioned above something is visible to all of you, like the buildings, Vehicles, Foods. Something that you can’t touch but will be able to feel or not like the time, temperature, events.

Well in programming each object has its attributes, and behavior. Objects are separate from one another as we expect them to behave. They are independent have their history and their own identity.

What are attributes in Objects?

As I said, Objects are independent due to their nature, they have their properties. For example, in the case of a vehicle, its model, color, year, and more. Their roles are to describe the current state of an object because each state is independent of the other. A vehicle might make by Toyota that’s red and another maybe blue.

How do they behave?

Behavior is certain action that the Object can perform. For example, in the case of a vehicle, it will be able to speed, stop, or horn. It’s important to remember that each has independent of the other.  To talk about Objects, Classes become inherently related.

What is a class, and how does it fit into our program?

Well, a class is a place where you can identify the behaviors and properties of an Object. The properties and behavior of an Object will be defined inside a class.

Abstraction, Encapsulation, Inheritance, and Polymorphism play a big part in object-oriented programming. This means that the focus starts on the common properties and behaviors of some Objects and left out the less important things. Separate the program into small pieces. Instead of creating different classes, we can instead create one generic class that has the common, and essential properties and behavior of those classes. use Polymorphism where an object can take the shape of many different forms. This is a very quick statement showing the stage of Object-Oriented Programming

From the blog CS@Worcester – Site Title by proctech21 and used with permission of the author. All other rights reserved by the author.

Introduction

This is my first blog, and I hope this is the beginning of many. I will post all my content here for discussion. We can agree that learning new tools help further your skills and ultimate power to greatness.

From the blog CS@Worcester – Site Title by proctech21 and used with permission of the author. All other rights reserved by the author.