0% found this document useful (0 votes)
2 views2 pages

Client Class Implementation in C#

The document defines a class hierarchy for managing clients, including an abstract base class 'Client' that implements the 'IComparable' interface. It includes two derived classes, 'ClientMoral' for corporate clients and 'ClientPhysique' for individual clients, each with their own properties and methods. Additionally, a 'ListeClient' class is created to manage a list of clients, allowing for adding clients and displaying them sorted by their ID.

Uploaded by

hlessabdelkabir
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Client Class Implementation in C#

The document defines a class hierarchy for managing clients, including an abstract base class 'Client' that implements the 'IComparable' interface. It includes two derived classes, 'ClientMoral' for corporate clients and 'ClientPhysique' for individual clients, each with their own properties and methods. Additionally, a 'ListeClient' class is created to manage a list of clients, allowing for adding clients and displaying them sorted by their ID.

Uploaded by

hlessabdelkabir
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

using [Link];

// Base class
public class Liste<T> { }

// Interface
public interface IComparable
{
int CompareTo(object obj);
}

// Abstract class Client implementing IComparable


public abstract class Client : IComparable
{
public string Adr { get; set; }
public int idCl { get; set; }

public abstract void Affiche();

public int CompareTo(object obj)


{
if (obj == null) return 1;

Client otherClient = obj as Client;


if (otherClient != null)
return [Link]([Link]);
else
throw new ArgumentException("Object is not a Client");
}
}

// Class ClientMoral inheriting from Client


public class ClientMoral : Client
{
public string NomGeran { get; set; }
public string RaisonSociale { get; set; }

public ClientMoral(string adr, int id, string nomGeran, string raisonSociale)


{
[Link] = adr;
[Link] = id;
[Link] = nomGeran;
[Link] = raisonSociale;
}

public override void Affiche()


{
[Link]($"Client Moral: {NomGeran}, {RaisonSociale}");
}
}

// Class ClientPhysique inheriting from Client


public class ClientPhysique : Client
{
public string NomCl { get; set; }

public ClientPhysique(string adr, int id, string nomCl)


{
[Link] = adr;
[Link] = id;
[Link] = nomCl;
}

public override void Affiche()


{
[Link]($"Client Physique: {NomCl}");
}
}

// Class ListeClient inheriting from Liste<Client>


public class ListeClient : Liste<Client>
{
private List<Client> clients = new List<Client>();

public void AfficherListeCl()


{
foreach (var client in clients)
{
[Link]();
}
}

public void AjouterClient(Client c)


{
[Link](c);
}
}

// Main Program
public class Program
{
public static void Main(string[] args)
{
ClientPhysique c1 = new ClientPhysique("Moez's address", 1, "Moez");
ClientMoral c2 = new ClientMoral("ISET's address", 2, "Nom Geran", "ISET");

ListeClient lcl = new ListeClient();


[Link](c1);
[Link](c2);

[Link](); // Sorting by idClient using CompareTo method


[Link](); // Displaying the list of clients
}
}

You might also like