cancel
Showing results for 
Search instead for 
Did you mean: 

different consumer component reuse the same instance of a sub component.

Former Member
0 Kudos

Hi All,

I have a question:

e.g. I have component A, B, C all define component usage of D.

if component D already has an instance D1, and I have a requirement to make A, B, C are using the same component usage D1.

How can I achieve this?

Regards,

Aaron.

Accepted Solutions (0)

Answers (1)

Answers (1)

ChrisPaine
Active Contributor
0 Kudos

two answers,

1) use the FPM - it does this sort of thing for you! If nothing else it would be a good reference on how to code for this. look at method ATTACH_COMPONENT_TO_USAGE of class CL_FPM_COMPONENT_MANAGER

2) define a overarching component for your application (or a singleton attribute) in which you can store the component usages. When you first create component D in any of A,B, or C, store this component usage in your overarching component so that you can refer to it later. Do as the FPM does and reuse the same usage. NB - this code isn't the simplest!

Hope that helps,

Chris

Former Member
0 Kudos

Hi Chris,

thanks for your very help answer.

But I think my case is a little different from the FPM manager.

I'm saying A, B ,C all define D component usage. to use the same component usage , that 'll be very easy, we just

use the entering referencing mode method. Here's the additonal precondition, an active component of the same type of component

usage D has already been instantiated before any of A, B, C instantiate component uage D, So what I need to do is to attach the

active Component instance to component usage D of A, B, C. I'm not sure whether this is possible.

Regards,

Aaron.

Edited by: Aaron Shen on Sep 6, 2010 6:15 AM

Edited by: Aaron Shen on Sep 6, 2010 6:16 AM

Edited by: Aaron Shen on Sep 6, 2010 6:18 AM

ChrisPaine
Active Contributor
0 Kudos

Hello,

I do not believe that there is any central accessible list of previously instantiated components. However if you made the assistance class of component D have a singleton public variable which contained a reference to the component instance (and ensured you checked this on "creation" of the component usage in A,B,C (and any other time you used this component)) then you could have a singleton component. But it would be a reasonable amount of work.

Given that components only exist for the lifetime of an application at most, I would be looking to have a framework, like the FPM to store your instances and reuse them.