ビジネスルールからのコード生成

<< 目次を表示 >>

ページ位置:  その他の記法・モデリング > ビジネスモデリング > ビジネスルールのモデリング > ビジネスルールの定義 >

ビジネスルールからのコード生成

ルールフロー図の全てのルールタスク要素に対してビジネスルールを定義した後は、ルールフローの振る舞いからソースコードを生成することができます。コード生成は、Enterprise Architectが内部に保持するコード生成テンプレートを利用して、ルールを保持するクラス要素に対して行います。

 

ルールフローの振る舞いから値を戻す

#

操作方法

1

プロパティサブウィンドウを表示した後、ルールフロー図の最後のノードの前の、最後に実行されるルールタスク要素をクリックします。

(参照:ビジネスドメインモデルの作成)

2

アクションタブを選択します。

3

「効果」の欄に、return文を記述します。

例: return true

4

保存ボタンを押し、その後OKボタンを押してダイアログを閉じます。

クラスからのコード生成を実行すると、ルールフローの処理の内容もソースコードとして出力されます。 (この例では、 Rental Systemクラスです。) 自然言語として入力された内容は、コメントとして出力されます。

 

 

例:

次のコードは、Rental Systemクラスに対してソースコード生成を実行した場合の結果です。

 

///////////////////////////////////////////////////////////

// RentalSystem.cs

// Implementation of the Class RentalSystem

// Generated by Enterprise Architect

// Created on: 26-July-2016 2:39:23 PM

///////////////////////////////////////////////////////////

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.IO;

 

    public class RentalSystem

    {

         public Customer m_Customer;

         public Car m_Car;

         public Rent m_Rent;

 

         public RentalSystem()

         {

         }

         ~RentalSystem()

         {

         }

         public virtual void Dispose()

         {

         }

         /* Begin - EA generated code for Activities and Interactions */

         public bool ProcessApplication(Rent m_rent,Application m_application)

         {

              // behavior is an Activity

              /*CAR MUST NOT BE RENTED TO CUSTOMERS WITHOUT A VALID LICENCE NUMBER*/

              if(m_Customer.ValidLicenceNumber == "FALSE")

              {

                   m_application.Status = "Reject";

                   m_Customer.Eligible = false;

              }

              /*CAR MUST NOT BE RENTED TO CUSTOMERS OF AGE LESS THAN 18*/

              if(m_Customer.age < 18)

              {

                   m_application.Status = "Reject";

                   m_Customer.Eligible = false;

              }

              /*CAR MUST NOT BE RENTED TO CUSTOMERS WITH BAD HISTORY LEVEL 3*/

              if(m_Customer.BadHistoryLevel == 3)

              {

                   m_application.Status = "Reject";

                   m_Customer.Eligible = false;

              }

              if (Customer.Eligible == true)

              {

                   /*RENT FOR SMALL CARS IS 80 AUD PER DAY*/

                   if(m_Car.type == Small)

                   {

                        m_rent.RentPerDay = 80;

                   }

                   /*RENT FOR AWD CARS IS 100 AUD PER DAY*/

                   if(m_Car.type == AWD)

                   {

                        m_rent.RentPerDay = 100;

                   }

                   /*RENT FOR LUXURY CARS IS 150 AUD PER DAY*/

                   if(m_Car.type == Luxury)

                   {

                        m_rent.RentPerDay = 150;

                   }

                   /*RENT PAYABLE IS CALCULATED AS THE PRODUCT OF RENTPERDAY AND RENTALPERIOD IN DAYS*/

                   m_rent.RentPayable = m_rent.RentPerDay * m_rent.No_of_rent_days;

                   if (CustomerBadHistoryLevel > 0)

                   {

                        /*PENALTY OF 20 % OF RENT MUST BE APPLIED FOR CUSTOMERS WITH BAD HISTORY LEVEL 2*/

                        if(m_Customer.BadHistoryLevel == 2)

                        {

                             m_rent.PenaltyFee = m_rent.RentPayable * 0.2;

                        }

                        /*PENALTY OF 10 % OF RENT MUST BE APPLIED FOR CUSTOMERS WITH BAD HISTORY LEVEL 1*/

                        if(m_Customer.BadHistoryLevel == 1)

                        {

                             m_rent.PenaltyFee = m_rent.RentPayable * 0.1;

                        }

                   }

                   else

                  {

                  }

                        /*TOTAL AMOUNT PAYABLE IS CALCULATED AS THE SUM OF RENT PAYABLE AND PENALTY IF ANY.*/

                        m_rent.TotalAmountPayable = m_rent.RentPerDay + m_rent.PenaltyFee;

              }

              else

              {

              }

              return m_application.Status;

         }

         /* End - EA generated code for Activities and Interactions */

    }

    //end RentalSystem

 

 

 

参照: