Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have Patient class and I am trying to create different classes for public patient and private patient, how to make all the classes work together?
Posted
Comments
SoMad 10-May-14 23:34pm    
What is the difference between a public and a private patient? Perhaps you don't need separate classes. It might just be some sort of 'patientType' enum property you add to your Patient class.

If you believe you need separate classes, it seems like a pretty simple matter of creating those two classes, derived from your existing class.

Soren Madsen
Sergey Alexandrovich Kryukov 11-May-14 0:32am    
Derive two patient classes from some base class and mark one of the with the access modifier "private" and another one with access modifier "public".
—SA

use base class as Patient and derive two classes from this base class called public and private patient.
You better read Introduction to inheritance, polymorphism in C#[^]

C#
public abstract class Patient
{
    //define your fields, make them potected if you need to access by sub classes  ( no need to have patient type field)
    //    protected Doctor assignedDoctor; // Doctor assigned to Patient
    //    protected static int pIdNo = 100000; // No get and set methods - internal use only
    //    protected String name;
    //    protected int age;
    // so on.....

    // define your constructors ( you don't need patient type as input)
    //create common methods whiich not depend on pationt types, like your SetIdentifier method
    //create abstract methods which depend on patient type
    public abstract bool AssignDoctor(ArrayList listOfDoctors);
    public abstract void Mv();
}

public class PublicPatient : Patient
{

    public override bool AssignDoctor(ArrayList listOfDoctors)
    {
        // impliment PublicPatient AssignDoctor
    }

    public override void Mv()
    {
        // impliment PublicPatient Mv
    }

    public override String ToString()
    {
        // impliment PublicPatient ToString
    }
}

// do the same for PrivatePatient  sub class 
 
Share this answer
 
v2
Comments
Member 10809541 10-May-14 23:40pm    
But how do I do that? I am trying to..its quite tough! any help?
DamithSL 10-May-14 23:46pm    
update the question with your Patient, public and private patient classes
Member 10809541 10-May-14 23:50pm    
is this your email address? damithsw[at]gmail[dot]com?? please check your email address!
Member 10809541 10-May-14 23:57pm    
please check your email.
DamithSL 11-May-14 0:04am    
this is not code writing or freelancer site, please try yourself and update the question with the code you try.
First, as SorenMad pointed out to you in his comment: consider if you really need two separate Classes.

Here's a rough-sketch:
C#
public abstract class Patient
    {
        // fields, properties, methods which both
        // Public and Private patients share are
        // defined/implmented here
        public Guid Patient_ID { private set; get; }
        public string Patient_Name { set; get; }
        public DateTime Patient_Dob { set; get; }
        public string Patient_Sex { set; get; }

        public Patient(string name, DateTime dob, string sex)
        {
            Patient_ID = Guid.NewGuid();
            Patient_Dob = dob;
            Patient_Name = name;
            Patient_Sex = sex;
        }
    }

    public class PublicPatient : Patient
    {
        // fields, methods, properties unique to PublicPatient go here

        public PublicPatient(string insurance, string name, DateTime dob, string sex)
            : base(name, dob, sex)
        {
            InsuranceCompany = insurance;
        }

        public string InsuranceCompany { set; get; }
    }

    public class PrivatePatient : Patient
    {
        // fields, methods, properties unique to PrivatePatient go here

        public PrivatePatient(string billTo, string name, DateTime dob, string sex)
            : base(name, dob, sex)
        {
            BillingAddress = billTo;
        }

        public string BillingAddress { set; get; }
    }
}
Keep in mind that an Abstract Class, in contrast to an Interface, can optionally implement methods, fields, properties.
 
Share this answer
 
v2
Comments
Member 10809541 11-May-14 0:58am    
BillWoodruff..I can't thank you enough. you're amazing! thanks for helping!
BillWoodruff 11-May-14 1:12am    
I only saw DamithSL's solution after I had posted mine, and I think you can learn a lot more from his example than you can from mine. I encourage you to accept his solution !

please note the change in the code in my solution (above) to:

Patient_ID = Guid.NewGuid();
DamithSL 11-May-14 1:27am    
5d!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900