From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c31acc89d296bc62,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsgate.cuhk.edu.hk!news.netfront.net!not-for-mail From: Marek Janukowicz Newsgroups: comp.lang.ada Subject: Design problem: generic package vs tagged subtype Followup-To: comp.lang.ada Date: Wed, 30 Jun 2010 19:52:58 +0200 Organization: Starware Message-ID: NNTP-Posting-Host: 89.174.12.152 Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: adenine.netfront.net 1277920380 13634 89.174.12.152 (30 Jun 2010 17:53:00 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Wed, 30 Jun 2010 17:53:00 +0000 (UTC) User-Agent: KNode/4.4.3 Xref: g2news1.google.com comp.lang.ada:12047 X-Original-Bytes: 4446 Date: 2010-06-30T19:52:58+02:00 List-Id: Hello everyone I'm struggling with some design problems in my project. To explain them I need to give some background on my project, so please bear with me. I'm developing a library to wrap relational database records into Ada objects (this kind of libraries are usually called "ORMs"). Generally I need following entities: - some type corresponding to database table (I called it "Model"). It's instances will hold records from that table, so it needs something to hold database column values as attributes. Operations generally need to be overridable. - something to map relationships between tables (associations) For Model I use a tagged type wrapped into generic package: generic Tbl_Name : String; type Attribute_Type is (<>); type Attribute_Type_Array is array (Attribute_Type range <>) of Attribute_Type_Type; Attribute_Types : Attribute_Type_Array; package Dar.Models.Base is type Model is abstract tagged limited record ... For associations I also use a generic package: generic with package Source_Model is new Dar.Models.Base(<>); with package Target_Model is new Dar.Models.Base(<>); Foreign_Key : String; package Dar.Models.Associations is function Find ... Here's where the trouble begins. Those Model subtypes tend to have quite a lot of custom logic, some operations overriden etc. and I can't add this to generic package instantiation, so I instantiate Dar.Models.Base inside another package: package Dar_Test.Models.Users is type Attribute_Type is (Id, Username, Email); type Attribute_Type_Array is array (Attribute_Type range <>) of Dar.Models.Attribute_Type_Type; package Base is new Dar.Models.Base( Tbl_Name => "authors", Attribute_Type => Attribute_Type, Attribute_Type_Array => Attribute_Type_Array, Attribute_Types => ( Id => Attr_Integer, Username => Attr_String, Email => Attr_String ) ); (some additional operations) ... What I don't like is that I have additional operations in Users package, but builtin operations in Users.Base (I want to make the design clean for programmers using my library). I don't like parametrizing Associations with Base instantiation. I think having just a tagged type (without a generic package Dar.Models.Base) and extending it would be better, but I don't know how to parametrize it with Attribute_Type type. I hope my description is not too vague. If you have any thoughts or think my approach is totally wrong please share your thoughts. Two additional (small) questions: 1. I'd like to replace type Attribute_Type_Array is array (Attribute_Type range <>) of Attribute_Type_Type in Dar.Models.Base specification with ... array (Attribute_Type'Range) ... to make sure full range of Attribute_Type is specified, but the compiler complains. Is there any other way to ensure that? 2. I have a type Attribute_Type_Type used to specify types of attributes (Integer, Date, String etc.). I then have a variant record: type Attribute_Value( Attr_Type : Attribute_Type_Type ) is record case Attr_Type is when Attr_Date => Date_Value : APQ_Date; when Attr_Time => Time_Value : APQ_Time; ... Is there any way to use builtin types here instead of Attr_Date, Attr_Integer, etc? Note that I need to specify type of each attribute in one array. Thanks in advance for reading my lengthy post :) -- Marek Janukowicz --- news://freenews.netfront.net/ - complaints: news@netfront.net ---