我有2個對象Area和SurfBreak。 Area有許多SurfBreaks,SurfBreak根據Area的風,浪潮和潮汐信息發佈其條件。這一點我做了一個很好的工作:-)面向對象編程方法問題
我現在有區域的預測數據列表 - 未來更改區域的屬性。
什麼是使用區域預測數據顯示Surfbreaks條件的最佳OOP方法?
非常感謝 安迪
----更新---
它的一個Rails應用程序
class Spot < ActiveRecord::Base
belongs_to :area
has_many :forecasts, :through => :area
def has_swell
wind = "#{area.swelldir}"
beachstart = "#{breakstr}"
beachend = "#{breakend}"
if ( ((wind.to_i) + 360 - (beachstart.to_i)) % 360 <= ((beachend.to_i) + 360 - (beachstart.to_i)) % 360 )
"#{area.swelldir} Has Incoming swell "
else
"#{area.swelldir} No Swell"
end
end
class Area < ActiveRecord::Base
has_many :spots
has_many :forecasts
class Forecast < ActiveRecord::Base
belongs_to :area
的數據庫表在軌的對象。我有Area和Spot很好地工作,但我現在想要顯示某個地點的預測。這是我不確定的一點。
mysql> desc areas;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| descrip | varchar(255) | YES | | NULL | |
| winddir | int(11) | NO | | NULL | |
| windspd | int(11) | NO | | NULL | |
| swelldir | int(11) | NO | | NULL | |
| swellhgt | float | NO | | NULL | |
| tide | int(11) | NO | | NULL | |
| lat | float | YES | | NULL | |
| lng | float | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)
mysql> desc spots;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| descrip | varchar(255) | NO | | NULL | |
| breakstr | int(11) | NO | | NULL | |
| breakend | int(11) | NO | | NULL | |
| offstr | int(11) | NO | | NULL | |
| offend | int(11) | NO | | NULL | |
| besttide | int(11) | NO | | NULL | |
| area_id | int(11) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
mysql> desc forecasts;
+--------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| forecastdate | datetime | YES | | NULL | |
| area_id | int(11) | NO | | NULL | |
| winddir | int(11) | NO | | NULL | |
| windspd | int(11) | NO | | NULL | |
| swelldir | int(11) | NO | | NULL | |
| swellhgt | float | NO | | NULL | |
| tide | int(11) | NO | | NULL | |
+--------------+----------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
所以說一個區域在數據庫中有24個預測行,在未來每小時一個。在我的應用 什麼是輸出點預測條件的最佳方式。在不改變「區域」相關值的情況下,「區域」保持現有條件。我可以通過改變Area對象的數據將所有的預測數據放到一個數組中循環,但是這對我來說看起來不太符合OOP?
由於輸出I像
Current Spot Details (Using spot methods on Area attributes)
xxx
Forecast Details for this spot (Using spot methods on Forecast attributes)
Hour 1 xxx
Hour 2 xxx
Hour 3 xxx
..
對不起後我這是不是很好的解釋。
問候 安迪
我們需要查看代碼才能幫助您。 – hvgotcodes 2010-12-03 17:30:43
我已經添加了一些更多的信息 – AndyM 2010-12-03 19:36:20