Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

The appropriate class structure to hold this?

I have a KPI which consists of a set of measures which are scored in different ways but each of which use some of the same data to determine a score.
So far I have a VB .net class:

Class KPI
    public property DateStart as datetime
    public property DateEnd as datetime
    public property CVSent as cPerformance
    public property SalesLeadsGenerated as cPerformance
    public property Interviews as cInterest
    public property ClientCalls as cInterest
End Class

cPerformance and CInterest inherit from another class cScore.  Each of these has a score property which includes its own particular way of determining a score but common to both, they need DateStart/DateEnd from the creating class order to calculate the score.
This suggests to me that either these classes need a reference to their creator or the values passing as constructors.
I wanted it so that when we 'Get' the score it calculates and that makes me think its not really a constructor I want to use since the datestart and dateend may be altered after construction which will affect the score.

So there for I am leaning towards passing a reference to the parent class but from what  I understand this is bad practice and there is probably right way to do it...
Can anybody suggest what I should be doing or confirm if this is the right approach?
0
dgloveruk
Asked:
dgloveruk
  • 2
  • 2
2 Solutions
 
käµfm³d 👽Commented:
So there for I am leaning towards passing a reference to the parent class but from what  I understand this is bad practice...
As with anything code-related, you have to be mindful of how you do it, but I don't see anything (necessarily) incorrect with doing that. However, if you do add a reference to the calling class, you will be adding a dependency to this class, and you will have to be prudent with changes you make to the class(es).

Is there a compelling reason to not pass these data values via the constructor (or even a method)?
0
 
dgloverukAuthor Commented:
I read an article which specified something about passing objects by reference created a lot of overhead.
I was thinking about that dependency issue and it made me think that if I wanted to score against perhaps another class it would become a burden.
I have opted in the end to repeat the information in the child class that is necessary for it to work.  In doing this despite the duplication, it does make the class more reusable.

Thanks for your input!
0
 
käµfm³d 👽Commented:
Classes in .NET are always passed by reference. Structs are passed by value. There is (typically) more overhead with a struct because a copy of the struct is created before it is passed.
0
 
dgloverukAuthor Commented:
As above
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now