top of page

3. Polymorphism: Flexibility in Business Operations

  • Writer: Puneet Malhotra
    Puneet Malhotra
  • Nov 14, 2024
  • 4 min read

Quick Recap: 🔁

In the prior topic, we explored how a businessman implemented an Inheritance strategy to centralize control over his business. As the business expanded, the owner encountered mismanagement and a loss of control. Through Inheritance, the owner can establish a foundational process and manage operations from a single location.


Flexibility and Freedom via Polymorphism


Over time, the owner is observing numerous changes and challenges in his business and the implementation of processes.


🤔 There are numerous situations where partners or franchisees desire to have same business processes but in customized way to suit their preferences.


Implementing customization isn't difficult, but managing and controlling it is challenging.

So, customization has to be done. But how? 🤔 🤔


Owner is not sure about the solution but needs to ensure that changes happen in a way that allows him to manage and control.


Customizations Required By Restaurants


Restaurant A : Need Payment in Cash

Restaurant B: Need Payment in Cash and Card Both

Restaurant C: Need Loyalty system as well


Base Process is same , which is Payment. But they need it in different way. So keeping everything at one place is becoming problematic.


Decentralized Approach

He think to give Payment method separately to each Restaurant while keeping other important function at base process.


  1. Payment_Base Only Cash 💰

  2. Payment_Restaurant_2: Cash + Card 💰+💾

  3. Payment_Restaurant_3: Cash + Card + Loyalty system


He has already done same previously using Inheritance. Its simple and sweet, so No confusion!


Here is the initial draft of his handwritten process.


ree

Is it Really a good solution? 🤔


👉 Payment is a crucial aspect of his restaurant business, he also wants to maintain centralized control over it. So customization Payment as per individual business needs can not be a better idea.


Same functions with multiple names! Very confusing, time-consuming to understand and manage. Not only for him but also for his managers. So, this approach must be rejected.

Although, above solution work for franchise owners but not good for his business management.

Hence, he take a closer look to requirement and try to find out a best solution.

What all three restaurant need, different type of same function. So by this logic, function name should not be changed.💡


Only the inputs which are different while method name can remain same

  1. Base : Payment method: Input: Cash

  2. UrbanBakery Payment method: Input: Cash, Card

  3. RealTasteBakery: Payment method: Input Cash, Card, Loyalty


There is only one Payment method with different types.


Business owner finds it simple, and customize input of each function as per their requirement while keeping the name of function same.

  1. Base  : paymentMethod: Input: Cash Output: remaining amount + receipt

  2. UrbanBakery : paymentMethod: Input: Cash, Card Output: remaining amount + receipt

  3. RealTasteBakery: paymentMethod: Input Cash, Card, Loyalty Output: remaining amount + receipt

One Function has many (Poly) forms.
ree

👉 This strategy prevents the business process from becoming cumbersome. It is now easier for business owners to manage the payment process, as it is established that the franchise will adhere to the payment process outlined in the base process by customizing the input (cash/card/loyalty).


Franchise owner consent to update processes, and the business continues accordingly.

Benefit of Polymorphism to Business


How can business management gain advantages by incorporating a name into the core process and encouraging partners to use these names? 🤔


Benefits of having Base Process


  1. Base process is like Index page of book which quickly guide about content or flow of any book. By seeing the Index one can tell about the Chapters or Topic a book has.

  2. Quick Visible: Base process can easily tell what are crucial process in use.

  3. Save Time: No need to check individual partner process.

  4. Centralize Control: Update or addition or removal to be happened only from base.

  5. Efficient Management: Managing large number of partners efficiently needs process small, simple, easy and centralized.


By doing so, he has better picture of this business.


  1. Monitoring: He can see what are the functions and methods are customized at process level.

  2. Flexibility: Process are not strictly bound to base process.

  3. Customized Business: While keeping function name same at base process, franchise can demand for customization.


Now there are two types of functions

  1. To be executed as-is, maintaining input according to the needs of each specific process.

  2. May be customized and specified according to the particular process.


I believe you have understood the gist of polymorphism in nonTech way. Now, lets see how we can translate this functional process into code.

Functional to Code


Let's explore how we can convert our business or functional knowledge into code.

public virtual class BaseRestaurant {

    // Function Overloading: Payment Method

    public void processPayment(String method) {

        System.debug('Base Payment: Processing payment using ' + method);

    }


    public void processPayment(String method, String cardType) {

        System.debug('Base Payment: Processing payment using ' + method + ' with card type ' + cardType);

    }



    public void processPayment(String method, String cardType, Boolean loyaltyApplied) {

        System.debug('Base Payment: Processing payment using ' + method + ', card type ' + cardType + ', loyalty applied: ' + loyaltyApplied);

    }


}

public class FranchiseA extends BaseRestaurant {

    String method = 'Card';
    String cardType = 'Visa';

    public void PaymentProcess() {
        processPayment(method, cardType);
    }
}
public class FranchiseB extends BaseRestaurant {

    String method = 'Card';
    String cardType = 'Visa';
    Boolean loyaltyApplied = true; // or false based on test

    public void PaymentProcess() {
        processPayment(method, cardType, loyaltyApplied);
    }
}

Thought-Provoking


How Polymorphism got discovered:-


Problems arrived first:

  1. Freedom , Flexibility and Customization

  2. Difficult control and management

  3. Risk to business due to freedom demanded by partners


Solution identified:

  1. Control from single location or base process

  2. Freedom and Flexibility


Design :

  1. Indexing: Keep names of required function ,which can impact business value, in base process

  2. Allow partners to override or overload to meet their need.


Comments


Check out my LinkedIn profile for professional introduction.

Drop Me a Line, Let Me Know What You Think
or Any other Technical topic you want to understand in NonTech style.

© 2025 by NonTech-Techie

bottom of page