多態可以”替代”資料庫中的欄位嗎?

來源:互聯網
上載者:User

今天在設計一個系統的時候,遇到這樣一個問題。

我想往資料庫中添加Employee,Employee有三種類型,結構如下:

Employee和PaymentClassification關聯,

HourlyClassification,SalariedClassfication,CommitionedClassification繼承PaymentClassification,

TimeCard和HourlyClassification關聯,SalesRecipt和CommitionedClassification關聯。

開始的時候我並沒有添加欄位儲存時哪種Employee,只是儲存Employee的基本資料,

後來,我從資料庫取得Employee的資訊時,我不能提供Employee類的屬性PaymentClassification資訊。

如果不在資料庫中用欄位儲存iswhichClassification的資訊,PaymentClassification的資訊從哪裡來呢?

我總是覺得用多態可以代替那個欄位,但是我不知道能不能實現,怎麼實現。

多態是運行時,資料庫是持久化,或許根本就不能。

我只是想區別PaymentClassification是哪種,這是多態的行為,當加入資料庫的時候,我是否要加一個欄位。

因為當我取得Employee的時候要決定他的屬性PaymentClassification是哪種,

但是我覺得是否可以不根據從資料庫取得欄位來設定PaymentClassification的種類,

而在程式中設定,只是要根據什麼設定呢?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.