Maxime Maxime - 3 years ago 127
C# Question

Deriving from PXGraph multiple time

I'd like to have some common logic shared between two screens, so I want to have an abstract class inheriting from PXGraph, and then two different Graphs inheriting from this abstract class.

Like this :

namespace LE
{
public abstract class ICarrySomeLogic : PXGraph<ICarrySomeLogic>
{
// common business logic
}

public class graph1 : ICarrySomeLogic
{
// specific business logic
}

public class graph2 : ICarrySomeLogic
{
// specific business logic
}
}


Does it work correctly ? Is there a "best practice" or another proper way to do it ?

Thanks a lot,

Answer Source

I have done this before and works great. Here is my example simplified...

public abstract class MyGraphBase<TGraph, TPrimary, TWhere> : PXGraph<TGraph, TPrimary> 
    where TGraph : PXGraph 
    where TPrimary : class, IBqlTable, new()
    where TWhere : class, IBqlWhere, new()
{
    public PXSelect<TPrimary, TWhere> document;
}

public class GraphOneEntry : MyGraphBase<GraphOneEntry, MyDac, Where<MyDac.docType, Equal<DocType.typeOne>>>
{
}

public class GraphTwoEntry : MyGraphBase<GraphTwoEntry, MyDac, Where<MyDac.docType, Equal<DocType.typeTwo>>>
{
}

My events in the base abstract class will fire and I can override as needed in the other graphs.

I have been using this since version 5.3

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download