Re: [fpc-pascal] FPC 3.0 + MIPS Linux

2015-11-27 Thread Mark Morgan Lloyd

Juha Manninen wrote:

According to this :
  http://forum.lazarus.freepascal.org/index.php/topic,30500.msg194271.html
FPC 3.0 MIPS version for Linux works through cross-compilation.
It is not mentioned in release notes. Android  + MIPS is mentioned.

I may buy a MIPS gadget later to see why Lazarus does not work.
I believe there will be more MIPS TV-box class computers in future.

Are there any news about FPC MIPS version that I should know about?


All I can say is that a couple of years ago I was able to confirm that 
both endiannesses of FPC worked on MIPS (hosted on Qemu) to the extent 
that they would self-build, but it wasn't quite up to Lazarus. The wiki 
page I (mostly) wrote 
http://wiki.lazarus.freepascal.org/Native_MIPS_Systems suggests this was 
actually November '12, which was probably fairly early in the lifetime 
of 2.7.1... I'd imagine a lot has changed since.


Imagination are aware of FPC and Lazarus and my contact there was 
generally enthusiastic when I last discussed it (probably ~18 months 
ago). However in view of the low price of their development boards I 
think the best thing would just be to get one and see how it works out, 
if there were some killer app that we could dangle in front of them it 
could work out well for everybody. http://store.imgtec.com/uk/


I don't off-hand know which endianness these boards are, I think the 
board used by the Debian MIPS maintainer is jumper-selectable. I've got 
a couple of SGI MIPS systems here but have never felt up to 
investigating an FPC IRIX port.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Marcos Douglas
On Fri, Nov 27, 2015 at 7:44 PM, luciano de souza  wrote:
> If I need to do "TAnimalFactory.create(atDog) as Tdog", perhaps, it
> would be better not to use a factory, doing simply "TDog.create".

You're right, use simply TDog.Create.
Why do you have a factory to create different types of animals
(classes)? Doesn't make sense. If you need a factory, you should use a
factory for dogs, another for cats and so on.
Another tip: Factories resolve some problems but there is a cost. The
factory will creates your instance (object) but it know only one
constructor, ie, the base class constructor.
Objects should be immutable at first place, only if you have a good
reason for don't use immutability. So, if they should be immutable,
you have only the constructor to instantiate your object, passing
arguments for it. If you have a constructor without arguments (using a
base class for example), you won't pass arguments to instantiate your
classe properly.
Another tip: use interfaces, not inheritance. Inheritance is evil. You
always will have problems using inheritance. Instead, use small
objects with few methods (2-5) to resolve just one problem. You don't
need inheritance for that. Your code will be more simpler and
customizable.
Decorator Pattern is more powerful than inheritance. Read about it.

Best regards,

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Marcos Douglas
On Fri, Nov 27, 2015 at 10:15 PM, luciano de souza  wrote:
> If I want to change the type of the instance, better is to use
> generics. A factory is only a batch builder of the same objects.

OK, but you don't need generics either ;)

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Marcos Douglas
On Fri, Nov 27, 2015 at 10:16 PM, Anthony Walter  wrote:
> if Animal is IBarkable then (Animal as IBarkable).Bark;

Your approach is much better, but don't use casting is even better
when we working with a true object oriented, because casting is a
"procedural command" for the compiler.


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Mattias Gaertner

One solution:

var
  animal: TDog;
BEGIN
  animal := TAnimalFactory.create(atDog) as TDog;
  try
animal.bark;
  finally
animal.free;
  end;
END.


Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Graeme Geldenhuys
On 2015-11-27 21:21, luciano de souza wrote:
> I'd like to understand how to implement the Factory Method pattern in Pascal.

See my "Simple Factory Pattern" article. I've written about many other
design patterns too.

  http://geldenhuys.co.uk/articles/


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread luciano de souza
Hello all,

I'd like to understand how to implement the Factory Method pattern in Pascal.

In my example, there are four classes:
1. TAnimal - The parent and abstract class;
2. TDog and TCat - The specialized classes;
3. TAnimalFactory - The class which creates instances of animals,
having received a enumerator as a parameter.

The method "live" is common to TAnimal, Tdog and TCat. However, "bark"
is found only in TDog.

In the following code, the compiler says that animal does not
possesses "bark" as a method. It's right. The behaviour is implemented
only in the derived class.

But, if this not works, how to implement the Factory Method in Freepascal?

program test;
{$mode objfpc}{$H+}

uses
tsbase;

var
animal: TAnimal;
BEGIN
animal := TAnimalFactory.create(atDog);
try
animal.bark; // Here is the error. If the call were "animal.live, no
errors would be shown. The code does not fails with (animal as
TDog).bark, but it does not make sense. The factory should allow to
create the instance only with the enumerator, without casting.

finally
animal.free;
end;
END.

unit tsbase;
{$mode objfpc}{$H+}

interface
type
TAnimal = class(TObject)
public
procedure live; virtual; abstract;
end;

TDog = class(TAnimal)
public
procedure live; override;
procedure bark;
end;

TCat = class(TAnimal)
public
procedure live; override;
end;

TAnimalType = (atDog, atCat);

TAnimalFactory = class(TObject)
public
class function create(AType: TAnimalType):TAnimal;
end;

implementation
{TDog}
procedure TDog.live;
begin
writeln('Um cachorro vive');
end;

procedure TDog.bark;
begin
writeln('Um cachorro foge');
end;

{TCat}
procedure TCat.live;
begin
writeln('Um gato vive');
end;

{TAnimalFactory}
class function TAnimalFactory.create(AType: TAnimalType):TAnimal;
begin
case AType of
atDog: result := TDog.create;
atCat: result := TCat.create;
end;
end;

end.

Well, I am studying design patterns, but I really does not understand
how to solve this problem.

I thank you for any tip.

Best regards,

-- 
Luciano de Souza
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread luciano de souza
Marcos,

Your answer and the excelent article of Graeme clarify the question.

If I want to change the type of the instance, better is to use
generics. A factory is only a batch builder of the same objects.

Graeme, your article opened my mind. The mappings and the registers
caused me a very strong impression. Thank you!
2015-11-27 21:48 GMT-02:00, Marcos Douglas :
> On Fri, Nov 27, 2015 at 7:44 PM, luciano de souza 
> wrote:
>> If I need to do "TAnimalFactory.create(atDog) as Tdog", perhaps, it
>> would be better not to use a factory, doing simply "TDog.create".
>
> You're right, use simply TDog.Create.
> Why do you have a factory to create different types of animals
> (classes)? Doesn't make sense. If you need a factory, you should use a
> factory for dogs, another for cats and so on.
> Another tip: Factories resolve some problems but there is a cost. The
> factory will creates your instance (object) but it know only one
> constructor, ie, the base class constructor.
> Objects should be immutable at first place, only if you have a good
> reason for don't use immutability. So, if they should be immutable,
> you have only the constructor to instantiate your object, passing
> arguments for it. If you have a constructor without arguments (using a
> base class for example), you won't pass arguments to instantiate your
> classe properly.
> Another tip: use interfaces, not inheritance. Inheritance is evil. You
> always will have problems using inheritance. Instead, use small
> objects with few methods (2-5) to resolve just one problem. You don't
> need inheritance for that. Your code will be more simpler and
> customizable.
> Decorator Pattern is more powerful than inheritance. Read about it.
>
> Best regards,
>
> Marcos Douglas
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>


-- 
Luciano de Souza
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Anthony Walter
type
  IBarkable = interface(IInterface)
  ['{B241068F-2ED9-43C7-066B-778B94CB58F9}']
procedure Bark;
  end;

  TAnimal = class(IInterface)
  end;

  TDog = class(TAnimal, IBarkable)
  public
procedure Live; override;
procedure Bark;
  end;

and later ...

if Animal is IBarkable then (Animal as IBarkable).Bark;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FPC Pestering Peacock (3.0.0) release

2015-11-27 Thread Juha Manninen
How to get ARM Linux version for Raspberry Pi?

BTW, you really should improve the download links.
Now a user can select his CPU / platform from here:
  http://www.freepascal.org/download.var
It looks good so far.
Then he selects eg. Intel/i386 - FreeBSD.
There is a top link for SourceForge which leads to project "Files"
section where the user must select his platform and the compiler
version (!) again.
Why? The link should lead to the right place instead.

Selecting one of the mirrors instead of SourceForge works better,
except that ARM Linux offers FPC 2.6.4.

Download link is important because it is the first impression for new
people trying FPC.
A louzy first impression affects for a long time.

Juha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] [fpc-other] FPC Pestering Peacock (3.0.0) release

2015-11-27 Thread Vincent Snijders
2015-11-26 22:44 GMT+01:00 Jonas Maebe :

> On 26/11/15 22:39, Florian Klämpfl wrote:
>
>> Am 26.11.2015 um 22:31 schrieb Jonas Maebe:
>>
>>> It just got posted on Slashdot too:
>>>
>>> http://developers.slashdot.org/story/15/11/26/1544243/free-pascal-compiler-300-is-out-adds-support-for-16-bit-ms-dos-64-bit-ios
>>> :) (it should appear on the front page soon)
>>>
>>
>> Nice work :)
>>
>> But people should be now update their svn or download 3.0.0 before the
>> servers get slashdotted :)
>>
>
> I mainly hope the wiki will survive :) Is there a way to temporarily put
> mediawiki in a static/read-only mode if necessary?
>

The wiki can be put in read-only mode by changing the $wgReadOnly variable
in the LocalSettings.php file. Anonymous users get a static file from the
cache, so no database trip is necessary for them.

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] FPC 3.0 + MIPS Linux

2015-11-27 Thread Juha Manninen
According to this :
  http://forum.lazarus.freepascal.org/index.php/topic,30500.msg194271.html
FPC 3.0 MIPS version for Linux works through cross-compilation.
It is not mentioned in release notes. Android  + MIPS is mentioned.

I may buy a MIPS gadget later to see why Lazarus does not work.
I believe there will be more MIPS TV-box class computers in future.

Are there any news about FPC MIPS version that I should know about?

Juha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal