Question

i have a Web App coded in ABAP / BSP. I´m interested to deliver fine code so maybe you can help my recognize some good or bad pattern. Actually i do following. Declare a base class object and instantiate it dynamically based on some parameter with a sub class. The base class has some methods for data fetching () the sub classes use this data and maybe manipulate it.

Here some fast basic picture (sorry dont think its conform to any standard or language but should give you an idea)

alt text http://img35.imageshack.us/img35/4351/designkdp.jpg

Is somthing like this OK? Is there any known pattern hidden or should i refactor and use a pattern? I like to here some suggestions. I have already read the Wikipedia article but i dont see a pattern fit exactly. (Also ordered some books but you guys are sure faster :) )

Was it helpful?

Solution

It seems a factory method

OTHER TIPS

The BaseClass and SubClasses seem to me like having something as (pseudocode)

interface IDataProvider{
  GetData();
}

class SubClass1 implements IDataProvider{
  GetData(){
     ...
  }
}

The instantiation strategies you use seem to work like a Factory. What you could do is to lay out rendering in some HTMLRenderingEngine or whatever (I'm not familiar with ABAP/BSP), just to have the presentation decoupled from the rest of the logic.

This is the Factory pattern from the book "Design Patterns: Elements of Reusable Object-Oriented Software" by Gamma, Helm, Johnson and Vlissides.

Inheritance is fun, but should be used as a last resort. I'm not saying you can't do it the way you did--your solution is totally valid, but just to suggest an alternative...

What if you had "DataClass" in which you could set a processData object (or not). The processData object would actually be an interface with a single method "processData".

When you call getData, it might look something like this:

if(processDataObject == null)
    return getInformation();
else
    return processDataObject.processData(getInformation());

Heck, if you have a "passthrough" processData object defined that does nothing and use that as the default "processDataObject", then the entire getData method becomes:

return processDataObject.processData(getInformation());

This would allow dynamic creation of classes to do any type of processing you want--It will simplify things that you build on top of this design.

This style of design took me a while to come to terms with, and you may not like the idea of avoiding inheritance at first, I'm just asking you think about it. My use of inheritance is pretty rare these days, and when I use it, it's always in very shallow trees.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top