0
\$\begingroup\$

BountyHunter has a secure line named JobLine that provides them with Prey to hunt.

The Prey can be changed at any time, either from the JobLine or changing circumstances that make the bounty hunter choose to swap targets.

How can I improve the dependent / calculated property that is being delegated from the BountyHunter to the JobLine ?

using Microsoft.Practices.Prism.ViewModel;
namespace TestBindings
{
 public class Prey
 {
 public Prey()
 {
 }
 }
 //Prey Provider
 public class JobLine : NotificationObject
 {
 public JobLine(Prey prey)
 {
 this.Prey = prey;
 }
 private Prey _prey;
 public Prey Prey
 {
 get { return _prey; }
 set
 {
 if (_prey != value)
 {
 _prey = value;
 RaisePropertyChanged(nameof(Prey));
 }
 }
 }
 }
 public class BountyHunter : NotificationObject
 {
 public BountyHunter(JobLine jobLine)
 {
 JobLine = jobLine;
 }
 public Prey Prey
 {
 get { return JobLine.Prey; }
 private set
 {
 if (JobLine.Prey != value)
 {
 JobLine.Prey = value;
 RaisePropertyChanged(nameof(Prey));
 }
 }
 }
 private JobLine _jobLine;
 public JobLine JobLine
 {
 get { return _jobLine; }
 private set
 {
 if (_jobLine != value)
 {
 _jobLine = value;
 RaisePropertyChanged(nameof(JobLine));
 RaisePropertyChanged(nameof(Prey));
 }
 }
 }
 }
}
asked Oct 16, 2017 at 1:28
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Per docs, NotificationObject is obsolete: [ObsoleteAttribute("Please use Prism.Mvvm.BindableBase")] \$\endgroup\$ Commented Oct 16, 2017 at 1:49

1 Answer 1

4
\$\begingroup\$

Is there any reason why you implemented the same logic/property twice? JobLine already has a property called Prey:

public Prey Prey
{
 get { return _prey; }
 set
 {
 if (_prey != value)
 {
 _prey = value;
 RaisePropertyChanged(nameof(Prey));
 }
 }
}

so why does BountyHunter have it too if I can access Pray via JobLine?

public Prey Prey
{
 get { return JobLine.Prey; }
 private set
 {
 if (JobLine.Prey != value)
 {
 JobLine.Prey = value;
 RaisePropertyChanged(nameof(Prey));
 }
 }
}
Heslacher
50.9k5 gold badges83 silver badges177 bronze badges
answered Oct 16, 2017 at 4:03
\$\endgroup\$
3
  • \$\begingroup\$ I think I may have over simplified my question. \$\endgroup\$ Commented Oct 16, 2017 at 4:19
  • 3
    \$\begingroup\$ @RyanTheLeach posting simplified code is never a good idea, it always backfires. You should post your real code. \$\endgroup\$ Commented Oct 16, 2017 at 4:26
  • \$\begingroup\$ @RyanTheLeach what t3chb0t said. And now if editing your question would invalidate this answer, please mark it as accepted and post a new question instead - with as much context as possible. MCVE's are for Stack Overflow, not this site. See how to get the best value out of Code Review for more information. \$\endgroup\$ Commented Oct 16, 2017 at 13:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.