English 中文(简体)
如何在实验室中书写这种等级结构? 组成、继承、决定
原标题:How should this Class structure be written in php? Composition, Inheritance, Decorator?

我有一个数据库,人们可以同时成为雇员、客户和公司成员。 我的行政管理系统允许我编辑<代码>Person 、EmployeeCustomer-Member上独立页的物体。

现在,我能够打电话到,但能够在同一页看到和编辑其雇员、客户和成员的财产。 对这一设想形成一种看法是微不足道的,但我要在正确确定基类、遗产、组成和总合时适当这样做。

我确实理解,雇员、客户和成员在没有个人的情况下就存在,因此,我想我应当创建一个新的类别:,即:composition。 我也希望利用这一新类别作为收集工作的一部分,以便我能够提出所有人员的名单,看看他们是否是雇员、客户还是成员。 某些字眼似乎不正确,我可以制定班级结构守则。 任何想法?

最佳回答

如同继承问题一样。 您有<代码>Person,但可以以更具体的措辞描述此人,例如。 Employee or Customer.

通常以目标为导向的方案拟订工作,你从基类开始(例如,<代码>Person/code>,然后在扩大子类时添加特性。 因此,<代码>Person可有名称、。 雇员人数() 客户

What you could do is implement a decorator pattern, and just keep building on your Person class. I m not sure how you re currently building people s profiles in your current application, but it would look something as follows in pseudo code:

<?php

$id = intval($_GET[ person_id ]);

$employee = new Employee(new Person($id));

届时将转至<代码>。 雇员()类别与雇员特有的额外财产和方法相关。

问题回答

暂无回答




相关问题
Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

C++ Class Inheritance problem

Hi I have two classes, one called Instruction, one called LDI which inherits from instruction class. class Instruction{ protected: string name; int value; public: Instruction(string ...

Overloading a method in a subclass in C++

Suppose I have some code like this: class Base { public: virtual int Foo(int) = 0; }; class Derived : public Base { public: int Foo(int); virtual double Foo(double) = 0; }; ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn t let me pass arguments to functions through event listeners, which makes me feel sad,...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual ...

热门标签