Solved

The appropriate class structure to hold this?

Posted on 2014-09-07
4
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

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 75

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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