Tuesday, January 4, 2011

Theorems Regarding Business Logic

In yesterday's Rigorous Definition of Business Logic, we saw that business logic can be defined in four orders:

  • First Order Business Logic is entities and attributes that users (or other agents) can save, and the security rules that govern read/write access to the entitites and attributes.
  • Second Order Business Logic is entities and attributes derived by rules and formulas, such as calculated values and history tables.
  • Third Order Business Logic are non-algorithmic compound operations (no structure or looping is required in expressing the solution), such as a month-end batch billing or, for the old-timers out there, a year-end general ledger roll-up.
  • Fourth Order Business Logic are algorithmic compound operations. These occur when the action of one step affects the input to future steps. One example is ERP Allocation.

A Case Study

The best way to see if these have any value is to cook up some theorems and examine them with an example. We will take a vastly simplified time billing system, in which employees enter time which is billed once/month to customers. We'll work out some details a little below.

Theorem 1: 1st and 2nd Order, Analysis

The first theorem we can derive from these definitions is that we should look at First and Second Order Schemas together during analysis. This is because:

  • First Order Business Logic is about entities and atrributes
  • Second Order Business Logic is about entities and attributes
  • Second Order Business Logic is about values generated from First Order values and, possibly, other Second Order values
  • Therefore, Second Order values are always expressed ultimately in terms of First Order values
  • Therefore, they should be analyzed together

To give the devil his due, ORM does this easily, because it ignores so much database theory (paying a large price in performance for doing so) and considers an entire row, with its first order and second order values together, as being part of one class. This is likely the foundation for the claims of ORM users that they experience productivity gains when using ORM. Since I usually do nothing but bash ORM, I hope this statement will be taken as utterly sincere.

Going the other way, database theorists and evangelists who adhere to full normalization can hobble an analysis effort by refusing to consider 2nd order because those values denormalize the database, so sometimes the worst of my own crowd will prevent analysis by trying to keep these out of the conversation. So, assuming I have not pissed off my own friends, let's keep going.

So let's look at our case study of the time billing system. By theorem 1, our analysis of entities and attributes should include both 1st and 2nd order schema, something like this:

 
 INVOICES
-----------
 invoiceid      2nd Order, a generated unique value
 date           2nd Order if always takes date of batch run
 customer       2nd Order, a consequence of this being an
                           aggregation of INVOICE_LINES
 total_amount   2nd Order, a sum from INVOICE_LINES
               
 INVOICE_LINES
---------------
 invoiceid      2nd order, copied from INVOICES
 customer         +-  All three are 2nd order, a consequence
 employee         |   of this being an aggregration of
 activity         +-  employee time entries
 rate           2nd order, taken from ACTIVITIES table
                           (not depicted)
 hours          2nd order, summed from time entries
 amount         2nd order, rate * hours
 
 TIME_ENTRIES
--------------
 employeeid     2nd order, assuming system forces this
                    value to be the employee making
                    the entry
 date           1st order, entered by employee
 customer       1st order, entered by employee
 activity       1st order, entered by employee
 hours          1st order, entered by employee

Now, considering how much of that is 2nd order, which is almost all of it, the theorem is not only supported by the definition, but ought to line up squarely with our experience. Who would want to try to analyze this and claim that all the 2nd order stuff should not be there?

Theorem 2: 1st and 2nd Order, Implementation

The second theorem we can derive from these definitions is that First and Second Order Business logic require separate implementation techniques. This is because:

  • First Order Business Logic is about user-supplied values
  • Second Order Business Logic is about generated values
  • Therefore, unlike things cannot be implemented with like tools.

Going back to the time entry example, let's zoom in on the lowest table, the TIME_ENTRIES. The employee entering her time must supply customer, date, activity, and hours, while the system forces the value of employeeid. This means that customer and activity must be validated in their respective tables, and hours must be checked for something like <= 24. But for employeeid the system provides the value out of its context. So the two kinds of values are processed in very unlike ways. It seems reasonable that our code would be simpler if it did not try to force both kinds of values down the same validation pipe.

Theorem 3: 2nd and 3rd Order, Conservation of Action

This theorem states that the sum of Second and Third Order Business Logic is fixed:

  • Second Order Business Logic is about generating entities and attributes by rules or formulas
  • Third Order Business Logic is coded compound creation of entities and attributes
  • Given that a particular set of requirements resolves to a finite set of actions that generate entities and values, then
  • The sum of Second Order and Third Order Business Logic is fixed.

In plain English, this means that the more Business Logic you can implement through 2nd Order declarative rules and formulas, the fewer processing routines you have to code. Or, if you prefer, the more processes you code, the fewer declarative rules about entitities and attributes you will have.

This theorem may be hard to compare to experience for verification because most of us are so used to thinking in terms of the batch billing as a process that we cannot imagine it being implemented any other way: how exactly am I suppose to implement batch billing declaratively?.

Let's go back to the schema above, where we can realize upon examination that the entirety of the batch billing "process" has been detailed in a 2nd Order Schema, if we could somehow add these facts to our CREATE TABLE commands the way we add keys, types, and constraints, batch billing would occur without the batch part.

Consider this. Imagine that a user enters a a TIME_ENTRY. The system checks for a matching EMPLOYEE/CUSTOMER/ACTIVITY row in INVOICE_DETAIL, and when it finds the row it updates the totals. But if it does not find one then it creates one! Creation of the INVOICE_DETAIL record causes the system to check for the existence of an invoice for that customer, and when it does not find one it creates it and initializes the totals. Subsequent time entries not only update the INVOICE_DETAIL rows but the INVOICE rows as well. If this were happening, there would be no batch billing at the end of the month because the invoices would all be sitting there ready to go when the last time entry was made.

By the way, I coded something that does this in a pretty straight-forward way a few years ago, meaning you could skip the batch billing process and add a few details to a schema that would cause the database to behave exactly as described above. Although the the format for specifying these extra features was easy enough (so it seemed to me as the author), it seemed the conceptual shift of thinking that it required of people was far larger than I initially and naively imagined. Nevertheless, I toil forward, and that is the core idea behind my Triangulum project.

Observation: There Will Be Code

This is not so much a theorem as an observation. This observation is that if your application requires Fourth Order Business Logic then somebody is going to code something somewhere.

An anonymous reader pointed out in the comments to Part 2 that Oracle's MODEL clause may work in some cases. I would assume so, but I would also assume that reality can create complicated Fourth Order cases faster than SQL can evolve. Maybe.

But anyway, the real observation here is is that no modern language, either app level or SQL flavor, can express an algorithm declaratively. In other words, no combination of keys, constraints, calculations and derivations, and no known combination of advanced SQL functions and clauses will express an ERP Allocation routine or a Magazine Regulation routine. So you have to code it. This may not always be true, but I think it is true now.

This is in contrast to the example given in the previous section about the fixed total of 2nd and 3rd Order Logic. Unlike that example, you cannot provide enough 2nd order wizardry to eliminate fourth order. (well ok maybe you can, but I haven't figured it out yet myself and have never heard that anybody else is even trying. The trick would be to have a table that you truncate and insert a single row into, a trigger would fire that would know how to generate the next INSERT, generating a cascade. Of course, since this happens in a transaction, if you end up generating 100,000 inserts this might be a bad idea ha ha.)

Theorem 5: Second Order Tools Reduce Code

This theorem rests on the acceptance of an observation, that using meta-data repositories, or data dictionaries, is easier than coding. If that does not hold true, then this theorem does not hold true. But if that observation (my own observation, admittedly) does hold true, then:

  • By Theorem 3, the sum of 2nd and 3rd order logic is fixed
  • By observation, using meta-data that manages schema requires less time than coding,
  • By Theorem 1, 2nd order is analyzed and specified as schema
  • Then it is desirable to specify as much business logic as possible as 2nd order schema, reducing and possibly eliminating manual coding of Third Order programs.

Again we go back to the batch billing example. Is it possible to convert it all to 2nd Order as described above. Well yes it is, because I've done it. The trick is an extremely counter-intuitive modification to a foreign key that causes a failure to actually generate the parent row that would let the key succeed. To find out more about this, check out Triangulum (not ready for prime time as of this writing).

Conclusions

The major conclusion in all of this is that anlaysis and design should begin with First and Second Order Business Logic, which means working out schemas, both the user-supplied values and the system-supplied values.

When that is done, what we often call "processes" are layered on top of this.

Tomorrow we will see part 4 of 4, examining the business logic layer, asking, is it possible to create a pure business logic layer that gathers all business logic unto itself?

30 comments:

Jonathan Bartlett said...

"This may not always be true, but I think it is true now."

It will always be true - this is a fundamental aspect of computer science. For a programming language to be Turing-complete (i.e. able to handle any calculating task), it has to allow for open-ended loops. Therefore, if your language is to allow for any calculating task, it must allow for open-ended loops. So, as long as there are new problems to solve, there will always be unparameterizable code.

Unknown said...

Prediksi Bola | Judi Online | Bursa Taruhan Casino | Taruhan Bola
Judi Bola Terpercaya | Bandar Bola Online | Agen Taruhan
Prediksi Bola | Judi Online | Agen Casino | Taruhan Bola
Casino Online | Agen Bola | Prediksi Dan Berita Sepakbola
Agen Bola Online | Bandar Bola | Agen Casino| Situs Judi
Agen Bola | Taruhan Online | Bandar Judi Terpercaya
Agen Bola | Taruhan Bola Online | Agen Casino Terpercaya
Taruhan Bola | Judi Online | Agen Casino Terpercaya
Agen Bola Online, Situs Judi Casino Online, Bandar Taruhan Bola
Agen Casino | Judi Online | Bursa Taruhan | Bandar Bola
Agen Judi Bola | Bandar Bola Online | Casino Online
Informasi Terupdate | Sumber Berita | Sumber Inspirasi
Berita Terbaru | Inovatif
Berita Bola | Prediksi Bola Jitu
Hanya Untuk Anda Pecinta Dunia Maya
Info Masa Depan | Ulas Bola Hari Ini
Info Terupdate | Berita Inovatif | Berita Pilihan
Prediksi Skor | Berita Bola | Jadwal Bola
Prediksi Bola | Pasaran Bola | Berita Bola Online
Informasi Terkini | Prediksi Dan Berita Sepakbola
Info Berita Terbaik | Bursa Taruhan
Berita Terhangat | Info Masa Depan
Berita Terupdate | Sumber Berita
Hasil Skor | Prediksi Bola Terpercaya
agen texas poker dan domino
bola pelangi agen bola sbobet
Judi Online
Taruhan Bola
Agen Casino
Bandar Bola
Agen bola, poker, judi on-line, Prediksi bola, togel

obat herbal ambeien akut said...

cara mengatasi berbagai macam penyakit secara alami
Obat Herbal Penurun Darah Tinggi Obat Herbal Ambeien Akut Obat Herbal Batu Empedu Tanpa Operasi Obat Herbal Sinusitis Kronis Obat Herbal Tumor Otak Jinak Obat Herbal Wasir Kronis Tanpa Operasi Obat Herbal Liver Kronis Paling Ampuh Obat Herbal Bronkitis Kronis Obat Herbal Usus Buntu Tanpa Operasi Obat Herbal Eksim Paling Ampuh Obat Herbal Gagal Ginjal Kronis

obat herbal glaukoma said...

pengobatan penyakit glaukoma secara alami tanpa operasi

Obat Herbal Glaukoma

obat herbal tbc said...

your post is very interesting
thank you for sharing
i really liked

Obat Herbal TBC

Unknown said...

Hi..its a useful information.
A well-managed email database is by far the best way to boost sales without risking budget waste because it appeals to consumers who have already opted in to receive marketing information from you. Germany Mailing Lists

cara install yii2 said...

Great Post, I'm just create tutorial iinstall yii2 framework too, check this cara install yii2

kumar said...

I agree with the most of the points in this article and it’s great without any doubt. I think you made some good points in Features also. Really an amazing post! I would like to suggest your blog in my friend’s circle. Here I find everything in details. I hope I will see this type of post again in your blog.
Engineering Colleges, ECE Engineering Colleges in Chennai

straightener said...

شركة مكافحة الصراصير فى دبى
شركة مكافحة حشرات في دبى
شركة تنظيف سجاد في دبي
شركة تنظيف بعجمان
شركة مكافحة حشرات فى عجمان

Lord Mark said...

Are you tired of being human, having talented brain turning to a vampire in a good posture in ten minutes, Do you want to have power and influence over others, To be charming and desirable, To have wealth, health, without delaying in a good human posture and becoming an immortal? If yes, these your chance. It's a world of vampire where life get easier,We have made so many persons vampires and have turned them rich, You will assured long life and prosperity, You shall be made to be very sensitive to mental alertness, Stronger and also very fast, You will not be restricted to walking at night only even at the very middle of broad day light you will be made to walk, This is an opportunity to have the human vampire virus to perform in a good posture. If you are interested contact us on Vampirelord7878@gmail.com

Elan said...

Nice Article ..Thanks for the information

Machine Learning Course in Chennai
Data Science Training in Chennai
Web Design Training in Chennai
Python Training in Chennai
Angular Training in Chennai
PySpark Training in Chennai
Android Training in Chennai
iOS Training in Chennai
DevOps Training in Chennai

Android Training in Chennai said...

Amazing Blog..Well Written.I really loved it..

RPA Training in Chennai
Selenium Training in Chennai
IoT Training in Chennai
Azure Training in Chennai
Data Science with R Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Informatica Training in Chennai

Ashwin said...

Nice article.keep post.Thank you
Machine Learning training in Pallikranai Chennai

Data science training in Pallikaranai

Python Training in Pallikaranai chennai

Bigdata training in Pallikaranai chennai

Spark with ML training in Pallikaranai chennai

Web Educare said...

This is a very good content and thank you for sharing such an wonderful information. Please follow my website for more information in Advanced SEO Training in Kolkata.

Digital Marketing Training.
Digital Marketing training institute.
Digital Marketing Agency in Kolkata.
Digital Marketing Services in Kolkata.
Advanced Digital Marketing Courses.
SMM Training in Kolkata.
SEO Training in Kolkata.

BTTI said...

Excellent Content. I am following your blog on a regular basis. Thank you for sharing this. Please follow my website for more information in Mobile Repairing Training Course.

Mobile Repairing Training in Kolkata.
Bike Repairing Training in Kolkata.
TV Repairing Training in Kolkata.
AC Repairing Training in Kolkata.
Computer Repairing Training in Kolkata.
AC Repairing Training in Kolkata.
CCTV Repairing Training in Kolkata.

IATRC said...

Very nice information. Really appreaciated. Thank you for the details. Please follow my site for PLC Training in Kolkata.

PLC SCADA Training in Kolkata.
PLC Training in Kolkata.
SCADA Training in Kolkata.
HMI Training in Kolkata.
VFD Training in Kolkata.
Industrial Automation Training in Kolkata.

Appsbit said...

Please keep sharing this types of content, really amazing. Please follow my website for more information in Best IT Professional Courses in Kolkata.

ANSIBLE Training in Kolkata.
DevOps Training in Kolkata.
CKA Training in Kolkata.
CKAD Training in Kolkata.
Docker Training in Kolkata.
Kubernetes Training in Kolkata.
AWS Training in Kolkata.
AZURE Training in Kolkata.
VMWARE Training in Kolkata.
Citrix Training in Kolkata.
NSX Training in Kolkata.
VDI Training in Kolkata.

Influx Infotech said...

Influx Infotech have Team of Experienced Software & Website Developers. That works for you so that you can easily run your business.
Website And Software Development Company
Best School Management Software ERP

IT Solution said...

nice work, website designing company in Gorakhpur

emailtaai said...

Software development company in Noida team has to perform in accord with the client's engineering team for ideal results. Techsaga Corporations address this facet of the software development process most aggressively with our streamlined and well-planned resources.

Michael Smith said...

I saw your site to be epic for my necessities. It has sensible and strong posts. I've killed by a wide edge an epic piece of them and took in a ton from them. You're achieving some astonishing work. Grateful to you fit for making a titanic confusing site. If you have some problem with Hp Printer Offline click the link.

forcracks said...

easeus data recovery crack
microsoft 2013 product key
mobiletrans crack
fabcon

Emblix solutions said...

Today, Emblix as one of the best and top most service-oriented Digital Marketing Agency in Hyderabad and India , Which provides high-quality result-oriented Digital Services ranging from SEO to Web Design, Social Media Marketing and more, to a broad spectrum of clients from diverse industry segments. Through a well-oiled combination of Quality Solutions, Transparent Pricing, helping brands connect with customers, Flexible Delivery & Contract Model with a firm commitment to deliver on time and to budget, Emblix has successfully built a strong relationship with clients based on mutual trust and respect. Further, Emblix’s extensive market experience and expertise in Digital Marketing helps clients in successfully managing data as a strategic asset.

MindMade-technologies said...

hi dude

thanks for the posting and very unique article . keep posting more useful topics and ideas

Jennifer Mofi said...

Some popular Gps devices like- Magellan devices like magellan maestro 3200,magellan roadmate 1440,magellan maestro 4040, magellan roadmate 5235t-lm,magellan roadmate 1700,magellan roadmate 1470, and other old and newer models. We’ll help you to get easy maps, software / Firmware updates.

Are you planning a trip or going out and wondering if you could have the latest maps to make your trip or your work. Well, you’re a step away from the latest map updates. Latest map updates make sure that you always reach your destination on time with full-proof accuracy.

aki said...

rpa uipath training in bangalore Are you looking for a training institute that offers the best prakalpana training in Bangalore? Look no further than Prakalpana Academy! Prakalpana Academy is the leading provider of prakalpana training in Bangalore.

We offer aem training in bangalore comprehensive training program that covers all aspects of prakalpana, from basic concepts to advanced techniques. Our program is designed to help you learn the skills and knowledge necessary to become a successful prakalpana practitioner.

pcb design training in bangalore Prakalpana Academy is located in the heart of Bangalore, close to all major transportation hubs.
We are open

aki said...

rpa uipath training in bangalore Are you looking for a training institute that offers the best prakalpana training in Bangalore? Look no further than Prakalpana Academy! Prakalpana Academy is the leading provider of prakalpana training in Bangalore.

We offer aem training in bangalore comprehensive training program that covers all aspects of prakalpana, from basic concepts to advanced techniques. Our program is designed to help you learn the skills and knowledge necessary to become a successful prakalpana practitioner.

pcb design training in bangalore Prakalpana Academy is located in the heart of Bangalore, close to all major transportation hubs.
We are open

Docker training Course in Bangalore Monday through Friday 9:00am to 5:00pm. Contact us today to schedule a consultation or register for our next class!

Essien said...


I must say you have done a very good job with this. In addition, the blog loads very fast for me on Internet explorer. Excellent Blog! Thank you so much for sharing. post utme form for elechi amadi polytechnic

Essien said...

Thank you for the wonderful business submit. It's nice to come across a blog from time to time that doesn't contain the same outdated and mashed-up information. Thanks so much for sharing. fuwukari cut off mark for information technology

pg slot said...

สล็อต เว็บ ตรง จากค่ายเกมสล็อตออนไลน์ชื่อดังอันดับ 1 ที่นักพนันทั่วโลกให้การยอมรับว่าเป็นค่ายเกมสล็อตออนไลน์ที่ดีที่สุดตลอดกาลกับค่าย PG SLOT ที่มาแรงที่สุดในปี 2022