As part of my work on a legacy C# application I've come across a novel (to me) use of an interface & concrete implementations. I can't think of any reason why you'd do the following, but I'm pretty thick, so maybe someone else can?
public interface IContract
{
ContractImplementation1 Contract { get; }
bool IsCollection { get; }
bool Touched { get; set; }
}
public class ContractImplementation1 : IContract
{
public ContractImplementation1(string
propertyOne, string propertyTwo, string propertyThree, string
propertyFour)
{
PropertyOne =
propertyOne;
PropertyTwo =
propertyTwo;
PropertyThree =
propertyThree;
PropertyFour =
propertyFour;
}
public ContractImplementation1 Contract { get
{ return this; } }
public bool IsCollection { get { return false; }
}
public bool Touched { get; set; }
public string PropertyOne { get; private set;
}
public string PropertyTwo { get; private set;
}
public string PropertyThree { get; private set;
}
public string PropertyFour { get; private set;
}
public override string ToString()
{
if
(string.IsNullOrEmpty(PropertyFour))
return string.Format("{0} => {1}: {2}", PropertyOne,
PropertyTwo, PropertyThree);
else
return string.Format("{0} => {1}: {2} {3}", PropertyOne,
PropertyTwo, PropertyThree, PropertyFour);
}
}
public class ContractImplementation2 : IContract
{
public ContractImplementation1 Contract { get {
return null; } }
public bool IsCollection { get { return true; }
}
public bool Touched { get; set; }
public List<ContractImplementation1>
Contracts = new List<ContractImplementation1>();
}
I can't get my head around the super-type having a property that is
a sub-type of itself.
Following Cosmin's answer: I can't get my head around why you'd
have the sub-type as a property given that the property returns
itself on the implementation (rather than a 'parent' of the same
type i.e. a different instantiation of the super-type).
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
As part of my work on a legacy C# application I've come across a novel (to...
Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...
Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...
Task 3: Main Program Create a main program class that: Creates three or more Nurse instances assigned to different shifts. Creates three or more Doctor instances. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created. Prints the toString() values for all employees. Prints the...
public class Car { /* four private instance variables*/ private String make; private String model; private int mileage ; private int year; // /* four argument constructor for the instance variables.*/ public Car(String make) { super(); } public Car(String make, String model, int year, int mileage) { super(); this.make = make; this.model...
I Have a problem with my JAVA class "Directivo". In the " public double sueldo() " method, the instruction say "Calculate the salary of a Directivo the following way: Invoke method salary of the father and add him the extra bonus" My question is : How can I do this ? how can i implement that instruction in the public double sueldo() method public class Directivo extends Planta implements Administrativo{ private double bonoExtra; public Directivo( String nom, String...
Im writing a method to evaluate a postfix expression. Using my own stack class. Here is my code but I keep getting a classcastexception where it says java.lang.Character cannot be cast to java.lang,Integer. Im not sure how to fix this. public class Evaluator { public static void evaluatePost(String postFix) { LinkedStack stack2 = new LinkedStack(); int val1; int val2; int result; for(int i = 0; i < postFix.length(); i++) { char m = postFix.charAt(i); if(Character.isDigit(m)) { stack2.push(m); } else { ...
C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...
Need help completing my instance method for deleteFront() as specified below To the class IntegerLinkedList, add an instance method deleteFront such that … Method deleteFront has no input. Method deleteFront returns … an empty Optional instance if the list is empty an Optional instance whose value is the integer that was deleted from the front of the list, otherwise Hints https://docs.oracle.com/javase/10/docs/api/java/util/Optional.html import java.util.Optional; public class IntegerLinkedList { private IntegerNode head ; private int numberOfItems ; public int getNumberOfItems() { return...
i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...