Startseite ¦  was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews ¦  sonstiges
kylix ¦  tutorials ¦  online shop ¦  fotos ¦  Add&Win Gewinnspiel


Willkommen Gast. Bitte einloggen oder registrieren.
08.02.2012, 03:15:56
Übersicht Hilfe Suche Einloggen Registrieren

+  SwissDelphiCenter Forum
|-+  English Forums
| |-+  General Forum
| | |-+  Mathematical Rings in OOP
« vorheriges nächstes »
Seiten: [1] Drucken
Umfrage
Frage: If you are really good at OOP in Delphi, I need your help
harley@umich.edu   -0 (0%)
harley@umich.edu   -0 (0%)
Stimmen insgesamt: 0

Autor Thema: Mathematical Rings in OOP  (Gelesen 2678 mal)
harleyflanders
Newbie
*
Offline Offline

Beiträge: 3


E-Mail
« am: 06.08.2007, 00:05:46 »

I would like to program a ring object, and am having problems getting started. Something like

type  Data = Pointer;  // ???

class TRing
  Zero: Data;
  function  Sum(Data, Data): Data; abstract;
  function  Product((Data, Data): Data; abstract;
  end;

The idea is to instantiate the functions Sum and Product later
to special cases where the ring elements are Real, Integer, Rational,
Real Polynomials, Complex,..

For a concrete problem, think of adding two vectors with elements in the ring.  I want to write the code only once, not repeat it for each kind of ring element:

type TVector = record
                          Dim: Cardinal;
                          Coord: array of Data;
 
function VectorSum(V, W: Vector): Vector;

var  K: Cardinal;

begin
with Result  do
  begin
  Dim := V.Dim;
  SetLength(Coord, Dim);
  for  K := 0  to  Dim - 1  do
    Coord[K] := Sum(V.Coord[K], W.Coord[K]);
  end;
end;

(Please ignore missing and incorrect details.)  I need help with the OOP
aspects of doing something like this.

Of course I have more ambitious things in mind, like matrix multiplication. 

If you have any ideas on how to go about this, please contact me at
harley@umich.edu.  Thank you.
Gespeichert
grenzgaenger
Global Moderator
Full Member
*****
Offline Offline

Beiträge: 232


« Antworten #1 am: 31.05.2008, 16:48:14 »

do you mean generics? they will come with delphi 2008. in the meantime, you can overload your methods.

<HTH> GG
Gespeichert
Loïs Bégué
Global Moderator
Hero Member
*****
Offline Offline

Beiträge: 1718



WWW
« Antworten #2 am: 02.06.2008, 14:00:31 »

... or overload operators...

About "generics" (D2007 required):  http://www.felix-colibri.com/papers/oop_components/delphi_generics_tutorial/delphi_generics_tutorial.html
About "overloading operators": http://www.aspfree.com/c/a/.NET/The-Delphi-Language-Part-2/10/

=> at least, you'll probably need to define/declare a basis class (or a common interface class). Then define subclasses...
Gespeichert

Prof.Y
Arpoon
grenzgaenger
Global Moderator
Full Member
*****
Offline Offline

Beiträge: 232


« Antworten #3 am: 08.06.2008, 11:11:01 »

Zitat von: Loïs Bégué
... or overload operators...

About "generics" (D2007 required):

So far I know, the generics will be a feature of D2008. I haven't D2007, so I can't prove it. You are sure, that you mean D2007?

kind regards
GG
Gespeichert
Loïs Bégué
Global Moderator
Hero Member
*****
Offline Offline

Beiträge: 1718



WWW
« Antworten #4 am: 09.06.2008, 09:37:31 »

At least, it is part of the features list... (I use D7 and D2006)
Gespeichert

Prof.Y
Arpoon
Seiten: [1] Drucken 
« vorheriges nächstes »
Gehe zu:  


Einloggen mit Benutzername, Passwort und Sitzungslänge

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006, Simple Machines LLC Prüfe XHTML 1.0 Prüfe CSS