OOP Concepts (Using Getters and Setters)
I am a dedicated and skilled Software Engineer specializing in mobile app development, backend systems, and creating secure APIs. With extensive experience in both SQL and NoSQL databases, I have a proven track record of delivering robust and scalable solutions.
Key Expertise:
Mobile App Development: I make high-quality apps for Android and iOS, ensuring they are easy to use and work well.
Backend Development: Skilled in designing and implementing backend systems using various frameworks and languages to support web and mobile applications.
Secure API Creation: Expertise in creating secure APIs, ensuring data integrity and protection across platforms.
Database Management: Experienced with SQL databases such as MySQL, and NoSQL databases like Firebase, managing data effectively and efficiently.
Technical Skills: Programming Languages: Java, Dart, Python, JavaScript, Kotlin, PHP
Frameworks: Angular, CodeIgniter, Flutter, Flask, Django
Database Systems: MySQL, Firebase
Cloud Platforms: AWS, Google Cloud Console
I love learning new things and taking on new challenges. I am always eager to work on projects that make a difference.
In Object-Oriented Programming (OOP), concepts such as encapsulation, abstraction, and data hiding are essential for designing maintainable and scalable systems. Let's expand these ideas using a simple e-commerce platform example.
1. Encapsulation
Encapsulation refers to bundling data and methods that operate on that data into a single unit, usually a class. In an e-commerce platform, a class representing a Product would encapsulate details like product name, price, and stock, and provide methods to access and modify those details safely.
Example: Product Class
public class Product {
private String name;
private double price;
private int stock;
// Getter for product name
public String getName() {
return name;
}
// Setter for product name
public void setName(String name) {
this.name = name;
}
// Getter for product price
public double getPrice() {
return price;
}
// Setter for product price
public void setPrice(double price) {
if (price > 0) {
this.price = price; // Price should be positive
}
}
// Getter for stock
public int getStock() {
return stock;
}
// Setter for stock
public void setStock(int stock) {
if (stock >= 0) {
this.stock = stock; // Stock cannot be negative
}
}
}
Encapsulation ensures that:
Data like product price or stock is kept private and cannot be directly modified from outside the class.
Only public methods (getters and setters) can access or change this data. This ensures safe, controlled changes. For example, a product price cannot be negative because the setter method checks for it before updating.
2. Abstraction
Abstraction means hiding the complex details of how things work and showing only the necessary parts. In an e-commerce system, users don’t need to know how the system calculates taxes or discounts—they just need to see the final price.
For instance, when we have a method to apply a discount on the product price, users don’t need to know how the discount is calculated. The Product class can handle that internally using its methods, hiding the complexity from the user.
Example: Applying a Discount
public void applyDiscount(double discountPercentage) {
if (discountPercentage > 0 && discountPercentage <= 100) {
double discountAmount = (price * discountPercentage) / 100;
price -= discountAmount;
}
}
Here, the user can call applyDiscount(10) to give a 10% discount on the product, but they don’t need to understand how the discount is calculated. This keeps the internal working hidden, promoting abstraction.
3. Data Hiding
Data Hiding is a principle where data is kept private and protected from direct access. This prevents users or other classes from accidentally or intentionally altering sensitive data. In our example, the price and stock are private fields. These fields can only be modified through controlled methods like setPrice() and setStock().
By hiding the internal data, you:
Prevent Invalid Changes: For example, setting a negative price is disallowed in the
setPrice()method.Ensure Data Integrity: The product's
stockcannot go below zero because the setter checks this.
This is crucial in e-commerce, where incorrect data could result in customers paying the wrong amount or products going out of stock while still being listed for sale.
Example: Stock Management
public void reduceStock(int quantity) {
if (quantity > 0 && stock >= quantity) {
stock -= quantity; // Reduce stock if there is enough
} else {
System.out.println("Not enough stock");
}
}
This method hides the complex logic of how stock is managed and ensures that the internal state of stock remains consistent.
4. Modularity
Modularity refers to dividing a program into smaller, independent modules (or classes). In an e-commerce system, you would have separate classes for different parts of the platform like Product, Customer, Order, etc. Each class is responsible for a specific part of the system, making it easier to develop, test, and maintain.
For example, the Product class handles everything related to products, and the Customer class handles customer-related data. These independent modules interact with each other but remain self-contained. If you need to update the product-related functionality, you can do so without affecting the customer-related functionality.
Getters and setters in Java help enforce important OOP concepts in e-commerce systems:
Encapsulation: Keeps product data secure and manageable by bundling it within a class.
Abstraction: Simplifies complex operations like discount calculation for users.
Data Hiding: Ensures sensitive product details are not directly accessible, protecting the integrity of the data.
Modularity: Allows for a clear, organized structure, making the system easier to maintain.
These OOP concepts make software systems like e-commerce platforms more reliable, scalable, and easier to maintain over time(W3Schools.com)(FavTutor)(Tutorials Freak).




