oop - Java data structure design for data of different types represented by timescale -
i'm trying suss out object oriented design , have come across issue i'm finding weird, , i'm not sure of strategy structure data.
the api i'm accessing provides data follows:
<pair_name> = pair name = ask array(<price>, <whole lot volume>, <lot volume>), b = bid array(<price>, <whole lot volume>, <lot volume>), c = last trade closed array(<price>, <lot volume>), v = volume array(<today>, <last 24 hours>), p = volume weighted average price array(<today>, <last 24 hours>), t = number of trades array(<today>, <last 24 hours>), l = low array(<today>, <last 24 hours>), h = high array(<today>, <last 24 hours>), o = today's opening price source: https://www.kraken.com/help/api#get-tradable-pairs
the bit i'm having trouble working out how handle array(<today>, <last 24 hours>) bits. i'd have structure conformed each fits into. i'd separate them out in volume, totaltrades , highlow objects (or that) type today/last 24 hours varies (sometimes int double).
i thought i'd try either this:
public abstract class daytimeframedata { protected object today; protected object lasttwentyfourhours; } or this:
public interface daytimeframedata { object today = null; object lasttwentyfourhours = null; } then extending/implementing 1 of each data type. i'm not sure these make sense @ all.
can offer me pointers how go structuring this, please?
an interface specifies methods not fields, can't use approach. use this:
public class daytimeframedata { protected double today; protected double lasttwentyfourhours; } since double can represent integer. use objects of type fields.
public class pairinfo { protected daytimeframedata volume; protected daytimeframedata numberoftrades; protected daytimeframedata low; } however, if each of these needs own specific methods, may indeed make daytimeframedata abstract , extend each type. example:
public class numberoftrades extends daytimeframedata { /* methods , fields specific numberoftrades */ } if you'd restrict types of fields double or integer specific implementations, use generics:
public abstract class daytimeframedata<t extends number, l extends number> { protected t today; protected l lasttwentyfourhours; } an implementation can specify types allowed.
public class numberoftrades extends daytimeframedata<integer, double> { /* methods , fields specific numberoftrades */ } the above state today value integer, , lasttwentyfourhours value double. if both need same type, can 1 type parameter on daytimeframedata. note need use wrapper types (double, integer) instead of primitive types (double, int) in case.
Comments
Post a Comment