Customer Facing Applications is business software hosted on your machines customers can use through the internet or mobile networks to interact with your company. Some examples can be found here.
Using Object Oriented Programming For Custom Programming In A SaaS Application
In the SaaS world, often customers will want their own customizations into the source code specific to how they want to do business with your software.
Here is a point where object oriented programming stands out. By crafting your programming in such a way that basic functionality is enhanced - you can use different classes specific to particular customers for enhanced implementation.
Since we are going to potentially be using one of multiple classes, we need to have an interface describing the methods available in the class.
(As a note, in OOP, you usually always want to program to the interface!)
There are two simple id number generating methods available - one for an invoice number and another for a customer number.
interface IfcGenerateID: method public character GenerateInvoice(). method public character GenerateCustomer(). end. /* class IfcGenerateID */
Now we describe the generic class that all customers in the SaaS system will run usually.
/* Generic class to generate various IDs in the system. */
class GenerateID implements IfcGenerateID:
/* Generate an invoice number */
method public character GenerateInvoice():
return string (year(today))
+ "-"
+ string(month(today))
+ "-"
+ string(day(today))
+ "-"
+ string(etime).
end. /* method GenerateInfo */
/* Generate an customer number */
method public character GenerateCustomer():
return string (year(today))
+ "-"
+ string(month(today))
+ "-"
+ string(day(today))
+ "-"
+ string(etime).
end. /* method GenerateCustomer */
end. /* class GenerateID */
As you can see, this is pretty simple and straight forward in how it generates id numbers - based on the date and time.
However, now you have a client named Amduus who wants to modify how these numbers are created. They want to have an I in front of the invoice number and a C in front of the customer number. This way it is more obvious it is an invoice number or a customer number.
The usual development process is put in place and a new class based on the old class (inheriting) is created with these special behaviors specific to that customer:
/* Amduus customization class to generate various IDs in the system. */
class AmduusGenerateID inherits GenerateID implements IfcGenerateID:
/* Generate an invoice number - precede with an I so people using */
/* number automatically associate it as an invoice number. */
method override public character GenerateInvoice():
return "I" + super:GenerateInvoice().
end. /* method GenerateInfo */
/* Generate an customer number - precede with a C so people using */
/* number automatically associate it as a customer. */
method override public character GenerateCustomer():
return "C" + super:GenerateCustomer().
end. /* method GenerateCustomer */
end. /* class GenerateID */
Of course, now the question is - how do I tell the SaaS application which class to run for which customer?
This is the purpose of the dynamic new statement. Since we programmed to an interface, any variable defined as that interface can use any object that implements that interface.
Here we have a variable that identifies the customer as "Amduus." Any custom classes for that customer will be prefixed with Amduus*.cls so we know that code is specific to that customer.
Then it is merely a matter of searching for that specific class and instancing or defaulting to the original class:
define variable Customer as character no-undo. define variable GenerateID as IfcGenerateID no-undo. /* Set the Customer so we pull up the correct cls in the dynamic-new */ Customer = "Amduus". /* Pull up the appropriate class to instance */ if search (Customer + "GenerateID.cls") <> ? then GenerateID = dynamic-new Customer + "GenerateID" (). else GenerateID = dynamic-new "GenerateID" (). display GenerateID:GenerateInvoice() format "x(30)". display GenerateID:GenerateCustomer() format "x(30)". delete object GenerateID.
So you see, this is a way to enhance objects from base objects for the purpose of altering their behavior based on the customer using the program.
- Login to post comments
