English 中文(简体)
抽象阶级和子阶级的最佳积极继承战略
原标题:Best ActiveRecord inheritance strategy for abstract class and subclass

试图为这一具体问题制定最积极的继承战略:

我有一个抽象的班子,请打电话<条码>。

Message
  |- recipient
  |- sender
    body

我有两个分班级

ColorMessage < Message
  |- first_color
  |- second_color
    body (returns "#{sender.name} says #{first_color} > #{second_color}")

WeatherMessage < Message
  |- current_weather_adverb
    body (returns "#{sender.name} enjoys #{current_weather_adverb} weather")

我愿就所有<代码>提出一个问题。 信息,显示其身体,不必担心其具体类型。 基本处理<代码>Message作为接口。

我熟悉科学、技术和革新,是本案的正确解决办法吗?

感谢你们的帮助!

最佳回答

我认为这是对单一继承的适当利用。

你们可以索取信息。 所有或所有科罗尔马斯群岛和铁路都将照顾给你的物体。

问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签