Tag: Jason Sender

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation #2

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation #2

In a previous post by our guest writer Dr Jason Sender, he investigated improvements in Oracle Policy Automation rules by applying some of the principles of refactoring, and then he began to discuss Object-Oriented Design Patterns and Oracle Policy Automation, and their application in real-world contexts.

As before, this third article draws on the work and publications of Martin Fowler, which we discussed in the previous post, those of Joshua Kerievsky from his highly regarded book “Refactoring to Patterns”, and the ground-breaking work on design patterns called “Design Patterns: Elements of Reusable Object-Oriented Software”, which had four authors known collectively as the Gang of Four (GoF).

Before studying some further examples of patterns and their application to Oracle Policy Automation, it is probably wise to step back and take a broad view of the context. Computer science is often defined as dealing in abstraction, and software engineering as managing complexity, and the connection is that only by considering different parts of programs and systems as abstract concepts are we better able to manage complexity.

Object-Oriented Design Patterns and Oracle Policy Automation in Context

To put it in terms more related to our daily jobs, Oracle Policy Automation is often integrated with other systems that the Oracle Policy Automation developer does not need to understand, and can think of in abstract terms. A good example would be the Siebel CRM or Oracle Service Cloud database that Oracle Policy Automation may interact with, but about which the Oracle Policy Automation developer may not need to know anything – beyond understanding the available attributes for mapping and having a brief overview of the context. Abstraction is about ignoring irrelevant details, and this is often accomplished by what is a theme running through many design patterns, which is to: “encapsulate the concept that varies” (GoF, p. 54).

We often obtain abstraction in Oracle Policy Automation by using indirection (interposing an intermediate attribute) to encapsulate the attribute that varies. This allows us to “Program to an interface, not an implementation“, as the GoF (p. 18) term it, the rationale for which is that the implementation can be changed if other parts of the program only depend on the interface.

If you come, like some of us here on the OPA Hub Website, from a CRM background, you will be familiar with the concept whereby access to a CRM Object is provided through an interface, and the interface does not change even if the Object undergoes modifications (such as when using the GetMetadata Operation of the Oracle Policy Automation Connector Framework).

Although design patterns and refactoring techniques should serve the goals of reduced duplication, reduced complexity, and increased clarity, these goals can be in conflict, not just with each other, but with certain Oracle Policy Automation-specific goals. Take for example one of the stand-out benefits of Oracle Policy Automation: Policy Isomorphism. This means having the same form (i.e., you can copy and paste legislation or other source material directly into Microsoft Word, and base your rules on this and compare them side-by-side) and this is in tension with the concept of intermediate attributes (adding more attributes to increase clarity).

Object-Oriented Design Patterns and Oracle Policy Automation : Strategy and Template Patterns

With that in mind we return to another example of how Object-Oriented Design patterns can be applied to Oracle Policy Automation. The following extended example will be given to demonstrate how useful the Strategy and Template Method design patterns (which we adapt from the GoF book) could be in reducing the number of tables and increasing the flexibility of calculations. We show this extended example to demonstrate the size of the reduction in rules from applying these design patterns to Oracle Policy Automation. We start with an information collection screen and associated Boolean rules to derive values from the drop down list items:

Object-Oriented Design Patterns and Oracle Policy Automation 1

We then look at the top level goals for determining the total profit of the company, which is our main goal:

Object-Oriented Design Patterns and Oracle Policy Automation

These are then derived from three very similar tables of calculations, which are listed in succession below:

Object-Oriented Design Patterns and Oracle Policy Automation 3

Object-Oriented Design Patterns and Oracle Policy Automation 4

Object-Oriented Design Patterns and Oracle Policy Automation 5

Object-Oriented Design Patterns and Oracle Policy Automation : Implementing the Design Pattern

We can now alter this to implement our design pattern. We first create a main rule to determine the total profit:

Object-Oriented Design Patterns and Oracle Policy Automation 6

This is the Template Method pattern since it delegates a part of the algorithm – the tax factor, a newly created attribute. Then, we employ the Strategy pattern to effectively split up the tax factor into one of three algorithms (in effect, we are treating the tax factor as an algorithm and then applying Strategy to it). We do this by parameterising, based on type of company, using a feature called Apply Sheet that avoids multiply proven attributes by letting the parameter determine which Excel Worksheet applies:

Object-Oriented Design Patterns and Oracle Policy Automation 7

Then each of the subsequent tabs has a small table. As an example, here is the mining sheet. The others have identical structure and adjusted values for the tax factor.

For the Strategy and Template Method patterns, applying these design patterns has transformed our example rulebase into something much more easily extensible.

Object-Oriented Design Patterns and Oracle Policy Automation : Improved Maintenance and Clarity

If we were to create another sector (e.g., oil), it would be very easy to add on another sheet in the Excel Workbook and add it to the Apply Sheet. In fact, we could easily add another 20 sectors, whereas there would be a lot of time-consuming ‘find and replace’ work to do in the original, and we would have ended up with dozens of pages of rules. Moreover, the original algorithm had a lot of code duplication, as the same Boolean attributes were repeated in row after row in table after table.

Furthermore, if we had needed to add or remove conditions from the tables it would have taken extensive work in order to verify that each and every table was updated correctly. In the reformed algorithm, the conditions were written only once and these are easily changeable. And, we were able to eliminate three (possibly confusing) and unnecessary sub-totals relating to each of the company types. The unvarying part of the algorithm (the total revenue – the total cost) is now written once, rather than 15 times, and so it is easily changeable.

Finally, our new algorithm mentions only the tax factor. This means that if all tax rates were harmonised, a single tax rate declared, or a new formula implemented that did not depend on the company type, since we have encapsulated the part of the algorithm that varies, we could just delete the Excel table and introduce a new table for the tax factor that did not mention the type of company. This would not have been so easy to do with the original algorithm.

Once again, even from a very simple set of examples, it should be clear that Oracle Policy Automation rules will benefit from the targeted application of principles from programming – in this case, the Strategy and Template Method design patterns. For more information about the ideas discussed in this article, Dr Sender can be reached using his LinkedIn profile, at the end of this article.

Object-Oriented Design Patterns and Oracle Policy Automation : Going Further

The OPA Hub and Dr Sender are currently working towards the launch of advanced training based on his work. If you are interested, please take a moment to answer the 1 question survey below (if you have not already registered for the OPA Hub you can do that here before you answer). Thank you!

What kind of advanced OPA training would you be interested in attending?

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation

In a previous post by our guest writer Dr Jason Sender, he investigated improvements in Oracle Policy Automation rules by applying some of the principles of refactoring. Hopefully the short examples he gave revealed some of the increases in readability, maintenance and flexibility that you can build into your rules.Now, in the second article in this series, Dr Sender looks at Object-Oriented Design patterns and Oracle Policy Automation. This article draws on the work and publications of Martin Fowler, which we discussed in the previous post, and those of Joshua Kerievsky from his highly regarded book “Refactoring to Patterns”.

Design Patterns

Kerievsky makes two very important observations on design patterns. His first point is that, as he terms a section heading, “There are many ways to implement a pattern.” (Kerievsky, p. 26). This is key to what we shall see in this article, since with Oracle Policy Automation we should be aiming at implementing the core concept of a given design pattern, rather than strictly following the implementation example given in GoF (1995).

Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing software design patterns. It has been influential to the field of software engineering and is regarded as an important source for object-oriented design theory and practice…The authors are often referred to as the Gang of Four (GoF) (Wikipedia).

The second key point that Kerievsky (p. 32) makes is that: “In general, pattern implementations ought to help remove duplicate code, simplify logic, communicate intention, and increase flexibility. However…people’s familiarity with patterns plays a major role in how they perceive patterns-based refactoring.” So we see here both our aims in using design patterns, and a constraint (developer knowledge). Since OPA does not have objects and classes in the same sense as an object-oriented language, we should not expect a straightforward application to OPA.

In this article we will focus on one single pattern, known as the Adapter pattern.

Summary: “Convert the interface of a class into another interface clients expect.
Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.” (GoF, p. 139)

Let’s look at applying the Adapter pattern to Oracle Policy Automation rules.  At one level, translation is possible; Oracle Policy Automation can translate all its attributes into another language so that the rules can be used once and deployed in multiple languages just by translating the variables, statements, and similar features, while not rewriting the rules. This example from Oracle (2016) demonstrates this:

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation

As a second example, we can make a variable equal to another variable, or a Boolean true if another Boolean is true. For example:

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation 2

Here we have adapted the ‘the sky is blue’ to ‘the sun is shining’ (but not vice versa) and adapted ‘the value of the car’ to ‘the value of the vehicle’ (but not vice versa). It might be thought that this is pretty simplistic and not all that useful. The following example highlights more complexity, and, instead of simply adapting the interface, as the above examples do, it goes beyond that to override some of the adaptee’s behaviour:

 

Guest Post : Object-Oriented Design Patterns and Oracle Policy Automation 3

 

Here we have adapted the interface from ‘the storey of the building’ to two different interfaces, ‘the lift floor’ and ‘the elevator floor’. British lifts start at 0 (or G) and US elevators start on the 1st floor and do not have a 13th floor. So not only have we changed the interface, we have adapted the behaviour. The new variables can be used elsewhere in the policy model in place of the original one.

Object-Oriented Design Patterns and Oracle Policy Automation : Adapter Pattern Summary

The Adapter pattern seems “made for OPA”. When discussing the Adapter pattern the GoF (p. 142) stress that:

“Adapters vary in the amount of work they do…There is a spectrum of possible work, from simple interface conversion – for example, changing the name of operations – to supporting an entirely different set of operations.”

The examples shown in this article illustrated three aspects:

  • The first adapted the language that users would see
  • The second was an example of changing the name of an operation
  • The third supported a different operation but was also an Oracle Policy Automation-specific variant of what the GoF (1995) term “two-way adapters”, since it adapted two variables from one underlying one.

Each of the three examples has different costs and benefits. The language translation tightly couples the adaptee and adapter, while the changing of the name allows for the other variable to change how it is derived without changing the adapter (i.e., a level of indirection).

It is important to note that the one-way variable name change or Boolean name change simply allow a new term to be used, but these might very well be used in more complicated ways in rule tables (for variables) or rules (for a Boolean) where the adaptee’s value equalled the adapter’s value only in certain circumstances. The two-way adapter allowed for a single variable to be used to provide multiple adapters, thus minimizing code duplication.

The Bigger Picture

It’s worth stepping back at this point to understand the broader context.  Computer science is often defined as dealing abstraction, and software engineering as managing complexity, and the connection is that only by considering different parts of programs and systems as abstract concepts are better able to manage complexity.  For example, Oracle Policy Automation is often integrated with other systems that the Oracle Policy Automation  developer does not need to understand, and can think of in the abstract, like the database that Oracle Policy Automation may interact, but which the Oracle Policy Automation developer may not need to know anything about beyond mapping attributes in Oracle Policy Automation.

So abstraction is about ignoring irrelevant details, and this is accomplished by what is often the theme running through many design patterns, which is to: “encapsulate the concept that varies” (GoF, p. 54).  We often obtain abstraction in Oracle Policy Automation by using indirection (interposing an intermediate attribute) to encapsulate the attribute that varies.  This allows us to “Program to an interface, not an implementation“, as the GoF (p. 18) term it, the rationale for which is that the implementation can be changed if other parts of the program only depend on the interface.

Once again, even from a very simple set of examples, it should be clear that Oracle Policy Automation rules will benefit from the targeted application of principles from programming – in this case Object-Oriented Patterns. The best approach is not a slavish application, rather a pragmatic use of those best-suited to the unique nature of the Oracle Policy Automation platform.

For more information about the ideas discussed in this article about Object-Oriented Design Patterns and Oracle Policy Automation, Dr Sender can be reached using his LinkedIn profile, below. Look out for more articles about Object-Oriented Design Patterns and Oracle Policy Automation coming soon!

Worldwide
Logo by Southpaw Projects LLC