48
FoxTeach 2001 Basic Three-tier- application- building Session V18 Rainer Becker dFPUG, Germany

Basic Three-tier-application-building

  • Upload
    mrinal

  • View
    27

  • Download
    0

Embed Size (px)

DESCRIPTION

Basic Three-tier-application-building. Session V18. Rainer Becker. dFPUG, Germany. Who Am I?. German FoxPro User Group http://www.dfpug.de/forum German VFP DevCon FoxX Professional Wizards & Builders GmbH http://www.wizards-builders.com MVP, MCSD, speaker/writer - PowerPoint PPT Presentation

Citation preview

Page 1: Basic Three-tier-application-building

FoxTeach 2001

Basic Three-tier-application-building

Session V18

Rainer BeckerdFPUG, Germany

Page 2: Basic Three-tier-application-building

FoxTeach 2001

Who Am I?

• German FoxPro User Grouphttp://www.dfpug.de/forum

– German VFP DevCon– FoxX Professional

• Wizards & Builders GmbHhttp://www.wizards-builders.com

• MVP, MCSD, speaker/writer– But I am not bilingual !

Page 3: Basic Three-tier-application-building

FoxTeach 2001

Who are you?

Visual FoxPro Programmers trying to match the capabilities of the

tool against a confusing number real world request

Page 4: Basic Three-tier-application-building

FoxTeach 2001

Remember Windows DNA99?

HTMLHTML

WindowsWindows

ActiveActiveDocDoc

Client/ServerClient/Server

lokal tableslokal tablesCOM-ServerCOM-Server

COM-ClientCOM-Client

XML-transferXML-transfer

Page 5: Basic Three-tier-application-building

FoxTeach 2001

Basic Theory

The minimum of theory

(you might know already)

Page 6: Basic Three-tier-application-building

FoxTeach 2001

Access in/between Layers

• Within a tier, “no limitation“– Do not forget delayed instantiation

• Between tiers, limited access– “strict“– “linear“– “tree-structured“– Variant: “partially not transparent“

Page 7: Basic Three-tier-application-building

FoxTeach 2001

Example for linear structure

• Advantage: Every tier can be replaced

• Disadvantage: Every tier has compl. Interface Every tier visited on the way down

Application

Presentation

Session

Transport

Netw ork

Data Link

Physical

OSI 7-Layer Model

http - ftp - mail - telnet

TCP

IP

Data Link

Physical

TCP/IP Protocol

Page 8: Basic Three-tier-application-building

FoxTeach 2001

Example for strict structure

• VFP-interface with databinding

• Advantage: Faster to develop, more performance

• Disadvantage: Business tier can be bypassedData navigation problems

Page 9: Basic Three-tier-application-building

FoxTeach 2001

Words and Tiers

Important Words

• Request

• Notification

• Cache

Typical Tiers

• User Interface

• Business Logic

• Database

Page 10: Basic Three-tier-application-building

FoxTeach 2001

Replace Front-End

• No direct application access or• „Web Glue“ (=redundancy!)

Page 11: Basic Three-tier-application-building

FoxTeach 2001

Replace Backend

• No native record-locking• “Properties“ for each data field• “Views“ for each list

User interface app. logic logical DB physical DB

Page 12: Basic Three-tier-application-building

FoxTeach 2001

Replace Front- and Back-End

Page 13: Basic Three-tier-application-building

FoxTeach 2001

The only thing not changing?

• Your business logic is the only thing thats going to be re-used in all environments

• The „wall“ between GUI and BO gives wrong idea

Page 14: Basic Three-tier-application-building

FoxTeach 2001

Basic Implementation

Coding the first set of classes

Page 15: Basic Three-tier-application-building

FoxTeach 2001

Top-Down Implementation

• User interface layer– Unified GUI-superclass– GUI-classes, especially buttons

• Business object layer– BO-wrapper– Business logic and service classes

• Data Access layer– Data intermediate layer– Data access layer

Page 16: Basic Three-tier-application-building

FoxTeach 2001

Start the Application

• Base_Base– Just geterrortext

• Loader_base– Check_path, set_path (.cPath),

load_vcx (.cvcx), start_menu (.cmenu), program_end

• Small main program for class-libs and creation of loader class

Page 17: Basic Three-tier-application-building

FoxTeach 2001

Basic GUI Layer

Beware – it‘s a VFP-GUI !

Page 18: Basic Three-tier-application-building

FoxTeach 2001

GUI Baseclasses

• Usual interface classes - example reduced to:button, combo, form, label, spinner, textbox, toolbar

• Super-Baseclass for various redundant GUI methods– E.g. Init, got/lostfocus, rightclick

Page 19: Basic Three-tier-application-building

FoxTeach 2001

GUI Buttons

• Add, Delete, Save, Restore, First, Last, Next, Prev, Quit

• Button-group to be placed on form

• Toolbar with all buttons– Init to distinguish form / toolbar – Toolbar: height/width=23, caption=„“– Button: picture = „“

Page 20: Basic Three-tier-application-building

FoxTeach 2001

GUI Button Functionality

• cBO, cBOMethod, lEnableWhenChanged

• Click– GetBORef( .cBO ).&cBOMethod

• Refresh: If ! Isnull() = TripleLogic– GetBORef( .cBO ).IsChanged()

= .lEnableWhenChanged

Page 21: Basic Three-tier-application-building

FoxTeach 2001

.GetBORef( .cBO ).<method>

• GetBORef[1,0] is an array property with an access method

• BO-name arrives as a parameter• Call is forwarded and returns a

reference to a BO• Method-call can be added

– Can again call an array

• This is our tiny BO-wrapper

Page 22: Basic Three-tier-application-building

FoxTeach 2001

Toolbar

• Toolbar Manager Methods– Create, Destroy, Hide, Show,

Refresh

• Management by form– Init, Destroy, Activate, Deactivate,

Refresh

• Form additionally refreshs label– Setall lRefresh, assign calls refresh

Page 23: Basic Three-tier-application-building

FoxTeach 2001

Additional Form Methods

• QueryUnload important for unsaved data– Query all business objects on form

• Release has to call queryunload

• By the way: Place everything in a container, not on the form itself!

Page 24: Basic Three-tier-application-building

FoxTeach 2001

Business and Data Objects

First view on similarities between these layers and small

implementation to start with

Page 25: Basic Three-tier-application-building

FoxTeach 2001

Business Logic Layer

• Forwarding methods to Data Access Layer for persistence– Add, delete, first, next, last, prev– save, restore– ischanged– Returning return value

Page 26: Basic Three-tier-application-building

FoxTeach 2001

Data Access Layer

• Tablemove– add, delete, first, last, next, prev

• Tablework – save, restore

• Serviceclass for Open– Table, alias, order, readonly,

buffering

Page 27: Basic Three-tier-application-building

FoxTeach 2001

Business Logic

How and where to place the logic? Some side effects on database

and user interface...

Page 28: Basic Three-tier-application-building

FoxTeach 2001

Validation and Action

• User interface needs validation status without triggering resulting actions

• Validation and resulting action belong to different methods

• Multiple change reactions kill each other (“record-valid“-type logic)– time-based price list and parts list– Change gender/dates in medical

insurance

Page 29: Basic Three-tier-application-building

FoxTeach 2001

Placing redundant Logic

• Associate general functionality

• Aggregate services and cascade calls to them

• Use a service factory for alternate rule-sets

• Moved to separate session about aggregation vs. subclassing

Page 30: Basic Three-tier-application-building

FoxTeach 2001

Status Information

• Invalid records should be saved persistently

• Valid status of record depends on its role– Even more so in logical tables

Page 31: Basic Three-tier-application-building

FoxTeach 2001

Pointer Position

• Data-binding of VFP connects GUI with DATABASE– So you are “strict“, not “linear“, at

least for displaying information

• Business logic moves around in data and makes pointer position an important “state“ to restore

Page 32: Basic Three-tier-application-building

FoxTeach 2001

Performance Problems

Advantages in maintenance against reaching performance

expectations

Page 33: Basic Three-tier-application-building

FoxTeach 2001

Stateless and small

• Web servers / transaction servers love stateless, independent small objects

• Complex objects / business logics are seldomly stateless or independent– A large number of small objects is not

small any more by any means

• Not being stateless increases the loads of the business logic and the data tier

Page 34: Basic Three-tier-application-building

FoxTeach 2001

Delayed Instantiation

• You can delay instantiation not only for pages but for all tiers, but:

• “See everything“-interfaces (like „*“ in Client/Server) / complex calculations load everything at once

• interface therefore at least under performance aspects not really “independent“ from business logic

Page 35: Basic Three-tier-application-building

FoxTeach 2001

Generic “Treeviews“

• Complex hierarchical data does not allow for in-between-layers on any “available“ hardware

Page 36: Basic Three-tier-application-building

FoxTeach 2001

Conceptual Problems

Each tier has its own unanswered logical questions

Page 37: Basic Three-tier-application-building

FoxTeach 2001

Somehow Redundant Rules

• Interface– Default value, picture, enable/disable,

popups

• Business Logic– Cannot expect correct parameters due to

COM Server access without interface

• Data– Default value, Field valid, record valid,

calculated fields, referential integrity

Page 38: Basic Three-tier-application-building

FoxTeach 2001

Data Access in general

• Number of “standards“(ODBC, RDO, DAO, ADO, OLE-DB, ...) gives a hint to a real problem

• Access rights allow direct writes to database - bypassing business logic

• Read rights do not give any logical functionality or “sense“

Page 39: Basic Three-tier-application-building

FoxTeach 2001

Web Interface to different

• Field validation needs permanent fast access to web server

• Large lookups need high-speed connection or local table

BTW: Have you ever seen XML for data input forms and/or with basic validation definitions?

Page 40: Basic Three-tier-application-building

FoxTeach 2001

How to prepare for Multi-Tier?

If standards and designs change, how can I prepare my architecture

in a somehow stable way?

Page 41: Basic Three-tier-application-building

FoxTeach 2001

User interface depends on environment

• Interactive Interfaces– Windows Styleguide– Instantiated COM-Server

• Disconnected environment– Processing FOXISAPI-hit– Processing XML in WebService

Page 42: Basic Three-tier-application-building

FoxTeach 2001

Implementation depends on interface

• Single-Field-Validation– For interactive User Interface– For COM-Server

• Complete-Record-Validation– For Internet Access– For Web-Services

• You have to implement both!

Page 43: Basic Three-tier-application-building

FoxTeach 2001

Something has not changed...

• OLE, COM, COM+ (and maybe SOAP) is still the same basic concept...

• Provide an additional interface for disconnected environments

Page 44: Basic Three-tier-application-building

FoxTeach 2001

Additional Material

Where to go from here ? Where to find additional information ?

Page 45: Basic Three-tier-application-building

FoxTeach 2001

Companion CD

• Bo_base.vcx

• Gui_base.vcx

• Gui_button.vcx

• Reise.vcx (application example)

• Reise.dbc

• Reise.scx

• Reise_main.vcx

Page 46: Basic Three-tier-application-building

FoxTeach 2001

Visit other Sessions

• V12 “Developing N-Tier Applications with VFP” – Jim Booth

• V14 “Building World-Class Visual FoxPro COM Servers“– Kevin McNeish

Page 47: Basic Three-tier-application-building

FoxTeach 2001

FoxTeach Web Update Page

www.dbcentral.com

This session will have web updates. There will be a newer version of the code examples with heavy use of constants (see session V16).

Page 48: Basic Three-tier-application-building

FoxTeach 2001

Thank you!

Please remember to fill out your evaluation.