Solved

The appropriate class structure to hold this?

Posted on 2014-09-07
4
150 Views
Last Modified: 2014-09-13
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
Comment
Question by:dgloveruk
  • 2
  • 2
4 Comments
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 40309610
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
 

Accepted Solution

by:
dgloveruk earned 0 total points
ID: 40309629
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
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 40309640
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
 

Author Closing Comment

by:dgloveruk
ID: 40320688
As above
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now