|
|
|
Last
revision of this document: |
Business
Objects are entities that keep together data belonging to one
'business-area'; e.g. an invoice with a 'header' and several
'positions'.
Business Objects can contain data that is physically
stored on different database-tables.
For
the theory about Business Objects please consult Using
Business Objects to handle data-storage and retrieval.
The
General Class, which is developed in this step, contents all
variables and methods of a Business Object that are needed on both
the Client-Side and the Server-Side.
It also contains Constants to
signal a completion-status (either a completion as expected or
unexpected errors) of the method.
Preface:If
you came to this document to get a guideline for developing a
Business Object, I recommend to start with the document Business
Object, Overview – Advanced Java Fat-Client-Development
or go directly to the ToDo-List in document Business
Object, General Class – Advanced Java Fat-Client-Development.
As
classes for Business Objects have a critical mission within an
application, preference was given to performance if there has to be
made a decision between understandability and performance.
I hope,
that the comments placed in the code will help you to understand what
intention is behind the code.
Credits:Too
numerous to mention; the idea is available in dozens of versions –
I refined a lot of ideas into my system.
JS_FC01j
– Develop the Base Class for Business Objects
completed - and its prerequisites too.
To
get the ideas and the theory of Business Objects it is recommended
to browse the following documents:
Using
Business Objects to handle data-storage and retrieval
and
Business
Object, Overview – Advanced Java Fat-Client-Development.
Create
the General Class for the Business Object 'Project':Let
us start with a very small Business Object; it just contains 3
variables:
* the Project-Code which identifies the Project the
Error-Messages (designed later) are for;
* the Language-Code which
is the 2 character ISO-code for the language the Error-Messages are
and
* the directory where the file with the language-specific
Error-Message in XML-structure is written out.
To
create the class, right click onto the project 'JS_FC01' and select
>New>Class
Enter
the Package (js_errdb.bo),
the (Class-)Name (JS_ErrDB_Project_BO),
enter or 'Browse' the Superclass (js_base.bo.JSBS_BO)
and check that no checkbox is selected; then click the [Finish]
button.
Eclipse
has already generated a template and the individual code can be
entered.
Please see the code to be entered at JS_ErrDB_Project_BO
- or copy it from there ;-) .
A
list with the major steps to do follows.
Code
a method to copy the values from one object to another:Define
the business variables of the Business Object.
In this Business
Object only 3 variables exist:/*
*
Project-Code; that is a shortcut for the Project. */ public
String
ProjectCode
=
"";/*
*
Language-Code; that is the ISO-CODE for the language the
Error-Messages are in. */ public
String
LanguageCode
=
"";/*
*
Directory where the file with the language-specific error-messages
is
* written out when the file with the XML-structure is
generated. */ public
String
TargetDirectory
=
"";
Code
a method to copy the values from one object to another:A
method to copy all values from another Business Object (of the same
class) is needed by every Business
Object./*
* --------------------
*
Method to copy the values from another object into this object.
*/
public
void getJS_ErrDB_Project_BO(JS_ErrDB_Project_BO
parmJS_ErrDB_Project_BO)
{/*
* Use
the method of the super-class to copy the Common
Attributes,
* StatusCode and StatusMsg.
*/super.getJSBS_BO(parm);JS_ErrDB_Project_BO
ProjectCode
=
parm;JS_ErrDB_Project_BO.ProjectCode }LanguageCode
=
parm;JS_ErrDB_Project_BO.LanguageCode TargetDirectory
=
parm;JS_ErrDB_Project_BO.TargetDirectory
Code
a method to compare if the values of two Business Objects are
different:To
decide, if at least one Business Attribute was changed, a method to
compare has to be implemented.
Among others, this method is used
to enable or disable buttons or to decide, if the database really
has to be updated when the user sends a 'store' but has not changed
any values./*
* --------------------
*
Method to compare two Business Objects and check if
* at
least one of the Business Attributes is different. */
public
boolean isDifferent(JS_ErrDB_Project_BO
parmJS_ErrDB_Project_BO)
{
if
(this.ProjectCode.compareTo(parm)
JS_ErrDB_Project_BO.ProjectCode!=
0) return
true; if
(this.LanguageCode).compareTo(parmJS_ErrDB_Project_BO.LanguageCode
!=
0)return
true; if
(this.TargetDirectory).compareTo(parmJS_ErrDB_Project_BO.TargetDirectory
!=
0)return
true;return
false;
}
Next
Steps:With
the General Class finished, the derivation for the Client-Side can
be developed.
Aside from implementing the special methods for the
client side, the next step deals with defining the Business Object
as a variable in the class for the task frame and calling the
relevant methods when the user clicks the button for
'store'..
JS_FC01l
- Develop the Client-Side Class for the Business Object 'Project'.