Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

OO Design question's

Former Member
0 Kudos

Hi all,

i have four tables:

1. user tables

2. Machine (computer /blackberry... ) that will store user locale for every machine

user can have 4 of 5 machine with different locale in every machine

3. attributes

4. additional data.

All this tables is are related to user and machine,

i.e. i can create user in the table without create machine but i can't create

Racine without creating user ,and so on for attributes that relate for user and machine.

i build class for each table that i have .

and now i facing some issue's

1. Since i want in all method to do CRUD opretion (for instance create_user method in class user create_machine in machine class delete_user delete_attributes etc..)

there is a way instead of using different CRUD in any of the class to use something generic ?

2.Since that i cant for instance create machine without creating user before, I need class

business class that handle this issue i.e method that call to create user and after create machine. ,this is o.k. ?

Thanks a lot !

Nina

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

I guess, You need have the application specific Business classes which will handle your CURD operations. Because you need to call respective Persistent classes to perform your CURD operations.

You need to create a single Business Class which would handle all your CURD operations.

Create methods which can accept all your information. Like:

Method CREATE_USER will accept User and Machine details (more than one - as internal table)

In the method implementation, you get the Persistent object for User and Persistent Objects for all Machine records in the internal table (If any). Use the SET methods of the User's Persistent class to save the data in to its table. Use SET methods of the Machine Objects to save data into machine table. Do the commit to save your data.

Design all other CURD methods in the same way to perform its respective action like for Delete: DELETE_USER.

Regards,

Naimesh Patel

13 REPLIES 13

naimesh_patel
Active Contributor
0 Kudos

I guess, You need have the application specific Business classes which will handle your CURD operations. Because you need to call respective Persistent classes to perform your CURD operations.

You need to create a single Business Class which would handle all your CURD operations.

Create methods which can accept all your information. Like:

Method CREATE_USER will accept User and Machine details (more than one - as internal table)

In the method implementation, you get the Persistent object for User and Persistent Objects for all Machine records in the internal table (If any). Use the SET methods of the User's Persistent class to save the data in to its table. Use SET methods of the Machine Objects to save data into machine table. Do the commit to save your data.

Design all other CURD methods in the same way to perform its respective action like for Delete: DELETE_USER.

Regards,

Naimesh Patel

0 Kudos

HI ,

i create 4 classes for each table for doing CRUD for user , machine etc...

all class have specific constructor.

I build generic interface with method create delete update read etc...instead of using

specific create_user delete_user delete_machine methods etc.

now i want to build new class that can handle the logic.

The problem here is how to know for which context to call delete update or create

need your suggestion's

maybe via factory pattern ,i need an example.

Best Regards

Nina

0 Kudos

hi,

as you have already created an interface which contains create, delete methods as generic. and this interface is being implemented in your respective classes.

so stick to that and try to pass parameters to those methods and depending on the values of those parameters call the repective class methods.

Hope this will help you!!!

thanks & regards,

punit raval.

0 Kudos

Now, once you have created different Business classes which have your CURD methods you need to design the model class.

In the Model class, you need to have different methods E.g. to read the data, you can create a method READ_USER_DETAILS. Make a USER as the importing parameter in your class and make all your 4 tables as the exporting parameters. Now, in this method call your business class READ_ methods to get the data for the User, Machines...etc.

Same way you design all the required methods like CREATE_USER_RECORDS, MODIFY_USERS.. etc. In this methods, you call all the required methods from business classes.

From your application, you need to call this new methods which you have created in the MODEL class. E.g. you have a screen where you enter the USER and it would give you data in the table control or ALV. So, here in the ENTER event you need to call the method READ_USER_DETAILS from the MODEL class. Same way you need to call other methods based on the respective user action.

Regards,

Naimesh Patel

0 Kudos

HI Naimesh,

Since I create Specific crud class for all the table's that handle the persistence on the DB, and in case for instance I want to create method that bring the user machine's like u write :READ_USER_DETAILS (all the details from the tables) do i need to refer to all the classes spartly (to the read method's) this is o.k.? it's not expensive ? instead of select join ...

other issue is : if i want to create data for user, macine ,and attributes, (to full 3 from the 4 tables i had) do i need to create in the model class i.e. specific method like (create UserMacineAtt )

in the model class that do this oration?

Does it good design ?

Best Regards

Nina

0 Kudos

do i need to refer to all the classes spartly (to the read method's) this is o.k.? it's not expensive ? instead of select join ...

Yes it is costly. Use of persistent classes would be good when you are dealing with small number for records like One header and Several line items. (e.g. Creating a single material document or sales document). It would not be performance efficient when you are dealing with huge amount of data (E.g. Report to display all shipped orders in past one year).

if i want to create data for user, macine ,and attributes, (to full 3 from the 4 tables i had) do i need to create in the model class i.e. specific method like (create UserMacineAtt )

I would suggest to use the same method CREATE_USER.. to create any details in any of the table. You can check if the importing parameter has any value. If yes, than call the business method for that object. Like:


* If Machines is not initial
* create object machines...

* if attr is not initial
* create object attr...

*....

Regards,

Naimesh Patel

0 Kudos

HI Naimesh ,

I am sorry that i raise this issue again but i need to really understand the concept that

you are talking about.

when i create model class and i create method create_or_update_machine

i can use modify statement instead of create object machine and calling the method create_machine

the do the insert .

So what is the advantage of using the separate classes that doing CRUD.

Thanks Again

Nina

0 Kudos

The main advantage of these design would be the Layer technique. Because of this "Layers", your code is now more reusable.

You can use the MODIFY statement to create / update the database table, but there you loose working with the "Persistent Classes". Check this help to know more about the persistent services: http://help.sap.com/saphelp_nw04/helpdata/en/f5/a3682ebc6911d4b2e80050dadfb92b/frameset.htm

Now, if you don't want to use the persistent classes, you can use the normal SQL commands to do the database operation. But I would suggest you do in in the CURD methods of the Business Classes. E.g. instead of accessing the persistent class, you can now use the normal SQL command to get the records and pass it back to the caller.

Regards,

Naimesh Patel

0 Kudos

HI Naimesh,

Thanks,

So the last question from my side before i go to the implantation part.

Assume that this is the method that u want to expose outside how will u do that modeling without using the persistence class that provided by SAP ?

Create_or_update_machine
Delete_machine(this method also need to delete all the the app and attributes) 
Read_machine_data 
Create_or_update_app
Create_or_update_additional_data 
Read_user_details (all the data in the tables that related for specific user )
Read_user
Read_all_user

Note:

1. All the tables are related via user (foreign key).

2. there is option to create user alone in the user table but

there is no option to create machine without user or additional data.

Thanks a lot!

Best Regards

Nina

0 Kudos

Without the persistent classes, DELETE_MACHINE would use the DELETE command to delete the data sequentially from Attributes, Apps and Machine. If there is any error in any step, you do the Rollback otherwise commit your work. Same way implement all other methods.

READ_USER_DETAILS would be a join on the all your tables based on the single user input. You need to have all tables as the exporting parameter to expose your data. You can create a complex structure which would have all the required tables included in it.

You may create READ_USERS_DETAILS which will give you the data for multiple users. In this method, you accept the range of the user and expose the data. You can call the same method in the READ_USER_DETAILS by providing the single customer as the range to the input of the READ_USERS_DETAILS.

Regards,

Naimesh Patel

0 Kudos

HI Naimesh ,

Thanks,

But my question is how you going to model it.

One class with one interface ,or for every entity specific class and one control class that do the logic ,or...

i don't want to use sap persistence due do performance issue but i can do something similar if it good design.

Best Regards

Nina

0 Kudos

hi,

i think you are getting into trouble becoz of wrong table selection.

it would be better if you would create tables like:

1. user table for storing all the user specific info.

2. machine table for storing all the info about unique machine.

3. table specifying the relationship between the machine and user alongwith additional details and other attributes info.

so you can just use 3 tables instead of 4. and this is a actually a good design approach as it will give a wide scope to solve your problem easily.

as you need to work on only the relationship table to get all your information.

hope this will surely help you!!!

thanks & regards,

punit raval.

Former Member
0 Kudos

Hi,

Are your tables linked to each other by a Foreign Key Relationship? For example, USER Table is linked to MACHINE Table with the cardinality 1:m. Is there a design document defining all these relationship between the tables?

Well, if you have defined the Entity Relationship Diagram and have answers for the above questions you can use the Table Maintainance Generator Functionality of the SAP. This will generate all the necessary database access statements taking care of the Transaction features along with the Dialogs for accessing the Database.

Have a look at the following link for a detailed concept and useage of the TMG feature.

http://help.sap.com/saphelp_nw70/helpdata/en/a7/5133ac407a11d1893b0000e8323c4f/frameset.htm

Hope this helps.

Thanks,

Samantak.