How to develop a multiplexed software system

zhaozj2021-02-17  57

How to create a multiplexed software system

Translator's order: This article is an extension of the design mode "Template Method" template method to apply templates to the entire software development product. First abstract the business logic part of the core product of the software product, for different parts of different products, the core products call the hook assembly of hooks by hooks, as long as the contents of the hook assembly are changed. Different products are achieved. The key to development is the function of abstract core products. Of course, this kind of development thinking is also limited, not suitable for all development projects (the core of abstract all projects is meaningless), this development idea is suitable for product development in a field, the same field abstract core product There are actual use value.

Creating a reused component is the first step in learning how to create a reuse program ---- By Mike Cahn

If you have developed several software projects continuous, you will find that you have written a lot of duplicate code. When you recognize this, you will definitely generate the idea of ​​multiplexing code. In fact, many development teams have established their own codebases and build libraries to make it easy to apply them into new projects. Below I will tell how to increase multiplexes to a higher level: multiplexing the entire application

If you develop a particular business function or Specific Vertical Market, you will find that there is a lot of overlap between components that reuse the core code between customers, but different points between demands require you to develop every customer. A new system

Especially unfortunately, it is more complex maintenance to increase design and development time. For example, if you have multiple versions, you will face this problem: spread a bug fix, product increase function requires each customer designated Change and test, multiplexing group help, etc.! But if all the core logic of all applications is the same, why is it not better to reuse this part of the core logic?

The answer is that you can of course do it, develop a core product, and then you can use it between different functional layers without having to change the core code.

What is a hook?

A hook is where you set up the customer instantiation code. It is a method of calling to a custom component. A customized layer (hook component) needs to know what happens, or you need to modify the core product behavior. Your core products can be used to use hook calls

A typical application is: a hook method calls through the current context association of data and hook components, and the hook component handles this call to return the correct information.

When designing core products and hook assemblies, you have to allow them to keep loose coupling relationships, and will not affect the configured hook assembly in the future. You must also ensure that the new hooks can be implemented after the new hook calls, which can also perform the correct event when configuring the hook assembly.

Determine the core function:

When using a hook to create a core application, the first step of the assessment is to determine which things will be handled as the core. If the core product sets too little function, then you will have to repeat the universal function for each project, so Added a lot of workload! Duplicate code operations destroy the purpose of core applications development. But if you include universal features that are not all customers will be worse, all development projects will have a lot of problems when using core code, and finally you will have to modify core products.

In the later stage of the core product, the functions that have been portable than the removal of the function should not be added, but this may result in too conservative errors! Functionality that can be suitable for core products can be generated as a component that can be shared, you can also transplant it when you are ready

Determining the core application functionality is to define a process flow that all customers are universal, let us look at an example, suppose you are developing three systems, and they have a workflow based on mobile projects. In these three systems, users can execute "Next", from a work item to the next work item, the following is the detailed difference between the three systems: System 1: This system is just a mobile project to Next, but do not perform any operation

System 2: The system records the details of the work items and procedures in a legacy system, and writes a reference keyword from authorization (Legacy) to work items.

System 3: The system displays a check box for the user update before the work project is moved to the next step. If all the required operations of the user flag do not have successful completion, the system undo operation "Next" action

Chart 1 shows how functionalization is divided between core products and three different clients, in this example

The customer needs the following capabilities:

Use and update core product objects (in this example, finger project)

Interact with users

Change the workflow of the core product (such as revoking the current operation)

Connect other applications or components

These needs are very typical, you have to take into account all functions of your core products

Build a hook interface:

The parameters set inside the hook assembly depend on the context change, which is better than maintaining a bunch of hooks, so creating a universal hook interface is a good solution. Use variable collection or parameter array to adapt to different data types you will join. In the first parameter, the flag of the hook is stored. The first thing to work in the hook component is to explain this flag and then call the corresponding function or component, the following code implements this function by using the Select ... .case structure :

Listing 1: Core product call hook assembly (a small hook component)

'Constants Would Normal BE Defined In A Module Or Class

Const nextstep_start = "ns-start"

Const nextstep_selected = "ns-successd"

Const hook_ok = "ok"

Const hook_cancel = "ca Zancel"

'...

'User Just SELECTED Next Step Operation

ShookResponse = MobjhookComponent.callin (Nextstep_Start, _

MobjcurrentItem, Mobjcurrentuser, "")

...

'User Just Selected The Step To Move The Item To

ShookResponse = mobjhookcomponent.callin (Nextstep_Selected, _

MobjcurrentItem, Mobjcurrentuser, SSELECTEDSTEP

Hook Component Code:

'NOTE: Hook constants file would need to be incdaded

Function Callin (Byval Shookid As String, VParam1 As Variant, _

VParam2 As Variant, VParam3 As Variant AS String

Dim SretrnValue As String

Dim objWorkItem as CLSWORKITEM

DIM Objuser as Clsuser

DIM SSELECTEDSTEP AS STRING

ON Error Goto Callin_Handler

Select Case ShookID

Case nextstep_start

'Processing to be done when nextstep is first invoked

Set objWorkItem = VPARAM1

Set objuser = vParam2

Call writelog (SHOOKID, "ITEM ID:" & _

ObjWorkItem.WorkItemid & "User ID:" & _

Objuser.Userid)

SHOOKID = HOOK_OK

Case nextstep_selected

Set objWorkItem = VPARAM1

Set objuser = vParam2

SSELECTEDSTEP = VPARAM3

Call writelog (SHOOKID, "ITEM ID:" & _

ObjWorkItem.WorkItemid & "User ID:" & _

Objuser.Userid & "Step:" & vparam3)

'... do whatver processing is required ...

SHOOKID = HOOK_OK

Case Else

'Unknown hook, Possibly Introducesd to Product

'after this component. Written.

'Just Allow IT, But Do Nothing.

Call Writelog (SHOOKID, "Unrecognized Hook")

SretrnValue = HOOK_OK

End SELECT

Callin = SRETURNVALUE

EXIT FUNCTION

Callin_handler:

'Handle The Error ...

END FUNCTION

Sub Writelog (SHOOKID AS STRING, Stext As String)

DIM SfullText As String

SfullText = Time $ & "& Shookid &" & Stext

Debug.print SfullText

'Log to file used mainly for testing

'and for Diagnosing Production Systems

If isfileloggingon (shookid) THEN

'Output Log Info to Text File ...

END IF

End Sub (To BE Continue)

You can also use your familiar COM to implement this feature, they are very similar to the technology of assigning calling methods.

You must ensure that you do not need to recompile the existing hook assembly when you issue a new version of the core product, so the hook component should ignore all the hook flags that are not recognized and only return a simple "success" code (reference code list. ELSE section), through this method, the hook assembly simply performs an approved hook call for functional requirements, if you need to add a new hook call point for the core product in the future, the existing hook assembly does not need to change any behavior to add new In the "Next" example, the core product may call the hook in several execution points, for example: two examples will be: hook when the user requests the next operation and select the step name again, these two examples will be: hook

PARAM1

PARAM2

PARAM3

PARAM4

Next step started

"Ns-start"

Objuser

ObjWorkItem

""

Next Step Step SELECTED

"Ns-successd"

Objuser

ObjWorkItem

SSTEPNAME

Such a simple example, three variables (plus hook identifier) ​​may be enough, but in order to avoid the trouble of future interface changes, you always have to add more functions, the list 1 shows a Simple code for core products: a hook assembly, a hook call instance In order to perform the functions of the three check boxes, you should add a checkbox form from the hook component item, and calls: case nextstep_selected ' ... Cast variables and Call WriteLog () ... 'Show the checklist frmChecklist.Show vbModal If frmCheckList.AllRequiredItemsTicked Then sReturnValue = HOOK_OK Else MsgBox "You have not ticked all the" & _ "required items." & _ "Next Step cannot Continue, Vbexclamation Call Writelog (SHOOKID, "Cancel Sent Back -" & _ "All Required Items Not Ticked") SRETURNVALUE = hook_cancel endiff f ... More code hook components affect core products:

The core product is a demand setting point that may change, and then delegate their control to the hook assembly, then respond to the state returned by the hook component, the data object references When the hook component receives a reference to the data object, the core product needs to capture. What changes causing the hook assembly, if you do not want to hook the seed component to modify the parameters of an object, you can use a publicity object or lock object, or an object that sets some features before the call method, if you allow changes, the object can verify them. Or record them, when the method returns, verify them through the core product, such as the user needs to update a work item with the two hooks Case Next's and call writelog () ... Srefkey = getMainframeKey objWorkitem.WorkitemID) objWorkitem.Reference = sRefKey sReturnValue = HOOK_OK core product can then work item query object returned: mobjCurrentItem.ResetChangedFlag sHookResponse = _ mobjHookComponent.CallIn (NEXTSTEP_SELECTED, _ mobjCurrentUser, mobjCurrentItem, sSelectedStep) If mobjCurrentItem.Changed then 'Take appropriate Action, Such As Validating 'AND / OR Saving The Changes ... END IF Logic Control Hook Components You can return the value that affects the logic of core product, which is limited, for example: You can specify a set of hook components returned. (Cancel the current operation, display the standard dialog box), otherwise your core products and hook components produce tight coupling hazards. By predefining a flag that does not need to be changed, you can capture any possible returned values ​​for the core product to use interactions in a typical application based on Windows Forms, and the hook component can be released by VB form. When the user needs time to interact to the web application, the core product, and hook components need to run on the server, the VB form is not applicable, but you can use the following methods: By returning a URL for the core product, come Call a new Window browser, returning a URL that calls the browsing window to the core product, all from this window's subsequent requests can be called by non-core. Because this window is non-moderate, it is clear that a variable of nested first steps between core product screens and hook windows temporarily replaces the core product browser with a hook URL content. This is a very

The effective mode interface can be captured by the requested components that can be customized by the screen. When the control is returned to the core product,

Can store your own screen

转载请注明原文地址:https://www.9cbs.com/read-30371.html

New Post(0)