Application Development and Automation 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: 
Read only

[DESIGN PATTERN] Factory: Define Method Area

Former Member
0 Likes
503

Hi Guys,

I have a question regarding the Design Pattern:Factory. According my need the question is below as:


  1. I have the Abstract Class AAA with it own Abstract method that create objects (only one method).
  2. I have a Final Sub-Class  BBB with 20 instantiate methods + the inherited method from Class AAA.
    1. BBB->method_bbb1().
    2. BBB->method_bbb2().
    3. BBB->method_bbb3().
  3. I have a Final Sub-Class  CCC with 10 instantiate methods + the inherited method from Class AAA.
    1. CCC->method_ccc1().
    2. CCC->method_ccc2().
    3. CCC->method_ccc3().

Afterwards:

  1. Class BBB is instantiated through the Factory. The TYPE of BBB is AAA.
  2. Class CCC is instantiated through the Factory. The TYPE of CCC is AAA.

My question is:

How could I use the 20 methods of BBB without to declare them in AAA (without inheritance). Because, if I declare them in AAA, consequently they will be visible in CCC. And I don't want to ...

DATA BBB TYPE REF TO AAA. "Var Object BBB is type of Class AAA

DATA CCC TYPE REF TO AAA. "Var Object CCC is type of Class AAA

BBB = AAA=>Factory( 'BBB' ).

CCC = AAA=>Factory( 'CCC' ).


" I want to call, in that way:


BBB->method_bbb1().


CCC->method_ccc1().

CCC->method_bbb1(). " RAISE ERROR

I have found a way but I don't know if it's breaking the rules of the Factory Concept.

Have you got any idea?

Thank you in advance.

Rachid.

2 REPLIES 2
Read only

Former Member
0 Likes
458

Noone ?

Read only

0 Likes
458

Hi,

If you have declared the methods in abstract class as protected or public and if you are inheriting it to the sub classes, then the methods will be available in the subclasses. There is no way to restrict like few abstract methods needs to be inherited and others need not be inherited. The inherited classes are forced to implement the abstract methods.

In your scenario, i do not think there is a need of abstract class, as I assume that both of your classes does some stand alone logic( as per your question ) compared to the other and doesn't have any common operations. Could you please let us know about this in detail ?? What about INTERFACES ?, Please have a look into it.

Kesav