我有患者课程,我正在尝试为公共患者和私人患者创建不同的课程,如何使所有课程一起工作? [英] 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?

查看:85
本文介绍了我有患者课程,我正在尝试为公共患者和私人患者创建不同的课程,如何使所有课程一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有患者类,我正在尝试为公共患者和私人患者创建不同的课程,如何使所有课程一起工作?

解决方案

使用基础class as Patient,从这个名为public和private patient的基类派生出两个类。

你最好阅读继承介绍,C#中的多态性 [ ^ ]



  public   abstract   class 患者
{
// 定义您的字段,如果您需要按子类访问(不需要患者类型字段),请对其进行保护
// protected Doctor assignedDoctor; //分配给患者的医生
// protected static int pIdNo = 100000; //没有get和set方法 - 仅供内部使用
// 受保护的字符串名称;
// protected int age;
// 等......

// 定义构造函数(您不需要患者类型作为输入)
// 创建不依赖于pationt类型的常用方法,例如SetIdentifier方法
// 创建依赖于患者类型的抽象方法
public abstract bool AssignDoctor(ArrayList listOfDoctors);
public abstract void Mv ();
}

public class PublicPatient:Patient
{

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

public 覆盖 void Mv()
{
// impliment PublicPatient Mv
}

public 覆盖 字符串 ToString()
{
// impliment PublicPatient ToString
}
}

// 做同样的事情对于PrivatePatient子类


首先,正如SorenMad在他的评论中指出的那样:考虑一下你是否真的需要两个单独的类。



这是粗略草图:

  public  摘要 患者
{
// 字段,属性,方法
// 公开和私人患者分享
// 此处定义/实施
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 患者(字符串名称,DateTime dob, string sex)
{
Patient_ID = Guid.NewGuid();
Patient_Dob = dob;
Patient_Name =姓名;
Patient_Sex =性别;
}
}

public class PublicPatient:患者
{
// PublicPatient独有的字段,方法,属性到这里

public PublicPatient( string insurance, string name,DateTime dob, string sex)
base (名字,dob,性别)
{
InsuranceCompany = insurance;
}

public string InsuranceCompany {设置; get ; }
}

public class PrivatePatient:Patient
{
// PrivatePatient独有的字段,方法,属性到这里

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

public string BillingAddress {设置; get ; }
}
}

请记住,与接口相比,抽象类可以可选地实现方法,字段,属性。


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?

解决方案

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#[^]

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 


First, as SorenMad pointed out to you in his comment: consider if you really need two separate Classes.

Here's a rough-sketch:

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.


这篇关于我有患者课程,我正在尝试为公共患者和私人患者创建不同的课程,如何使所有课程一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆