Where to put the code?

Ben Tam 216 Reputation points
2020-12-30T06:12:48.657+00:00

I following the book "C# Tutorial" (https://video2.skills-academy.com/en-us/dotnet/csharp/tutorials/default-interface-methods-versions).
Since the book doesn't mention where the code should be placed, I just paste the code on a new tab "customer-relationship.cs".

51592-setloyalty.gif

The other codes are as follows.

ICustomer.cs

using System;  
using System.Collections.Generic;  
  
namespace customer_relationship  
{  
    // <SnippetICustomerVersion1>  
    public interface ICustomer  
    {  
        IEnumerable<IOrder> PreviousOrders { get; }  
  
        DateTime DateJoined { get; }  
        DateTime? LastOrder { get; }  
        string Name { get; }  
        IDictionary<DateTime, string> Reminders { get; }  
    }  
    // </SnippetICustomerVersion1>  
}  

IOrder.cs

using System;

namespace customer_relationship
{
// <SnippetIOrderVersion1>
public interface IOrder
{
DateTime Purchased { get; }
decimal Cost { get; }
}
// </SnippetIOrderVersion1>
}

SampleCustomer.cs

using System;
using System.Collections.Generic;

namespace customer_relationship
{
public class SampleCustomer : ICustomer
{
public SampleCustomer(string name, DateTime dateJoined) =>
(Name, DateJoined) = (name, dateJoined);

    private readonly List<IOrder> allOrders = new List<IOrder>();  

    public IEnumerable<IOrder> PreviousOrders => allOrders;  

    public DateTime DateJoined { get; }  

    public DateTime? LastOrder { get; private set; }  

    public string Name { get; }  

    private readonly Dictionary<DateTime, string> reminders = new Dictionary<DateTime, string>();  
    public IDictionary<DateTime, string> Reminders => reminders;  

    public void AddOrder(IOrder order)  
    {  
        if (order.Purchased > (LastOrder ?? DateTime.MinValue))  
            LastOrder = order.Purchased;  
        allOrders.Add(order);  
    }  
}  

}

Program.cs

using System;

namespace customer_relationship
{
// <SnippetIOrderVersion1>
public interface IOrder
{
DateTime Purchased { get; }
decimal Cost { get; }
}
// </SnippetIOrderVersion1>
}

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,815 questions
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,626 Reputation points
    2020-12-30T07:24:17.88+00:00

    Hi BenTam-3243,
    The document point that "You can see the entire finished code in our samples repo on GitHub."
    And we can see that the " public static void SetLoyaltyThresholds SetLoyaltyThresholds" code is placed in ICustomer.cs.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Viorel 116.5K Reputation points
    2020-12-30T06:27:42.027+00:00

    According to tutorial and used members, I think that you should put it inside ICustomer interface.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.