Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1532 > unrolled thread
| Started by | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| First post | 2013-07-31 09:29 +0200 |
| Last post | 2013-08-01 01:58 -0700 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.postscript
How to write ‘object oriented’ code Cecil Westerhof <Cecil@decebal.nl> - 2013-07-31 09:29 +0200
Re: How to write ‘object oriented’ code luser- -droog <mijoryx@yahoo.com> - 2013-07-31 00:56 -0700
Re: How to write ‘object oriented’ code luser- -droog <mijoryx@yahoo.com> - 2013-07-31 01:25 -0700
Re: How to write ‘object oriented’ code luser- -droog <mijoryx@yahoo.com> - 2013-07-31 01:28 -0700
Re: How to write ‘object oriented’ code luser- -droog <mijoryx@yahoo.com> - 2013-08-01 01:58 -0700
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2013-07-31 09:29 +0200 |
| Subject | How to write ‘object oriented’ code |
| Message-ID | <87iozrb31a.fsf@Aspire.decebal.nl> |
I am using postscript to generate quotes with borders. For example at:
https://www.facebook.com/CecilWesterhof
There are severall functions you need:
- drawing the actual border
- getting the height of the border
- getting the width of the left element
- getting the width of the right element
- getting the width of the center elements
Is there a (best) way that I can work like I am having classes? I just
make an assignment of the type of the border I want to use, and the
calls give the values belonging to that border.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-07-31 00:56 -0700 |
| Message-ID | <98c03d04-191a-4aa8-ab00-8b9aa179fc94@googlegroups.com> |
| In reply to | #1532 |
On Wednesday, July 31, 2013 2:29:37 AM UTC-5, Cecil Westerhof wrote: > I am using postscript to generate quotes with borders. For example at: > > https://www.facebook.com/CecilWesterhof > > There are severall functions you need: > > - drawing the actual border > - getting the height of the border > - getting the width of the left element > - getting the width of the right element > - getting the width of the center elements > > > Is there a (best) way that I can work like I am having classes? I just > make an assignment of the type of the border I want to use, and the > calls give the values belonging to that border. > For the simpler uses of Object-orientation (abstraction, encapsulation), you can use dictionaries for classes and objects. Here's a very simple example of an encapsulated turtle: http://stackoverflow.com/a/8624246/733077 And for serious OO in PS, this is the only Prior Work I've found, but the code needs modification since it uses non-standard operators: http://code.google.com/p/xpost/downloads/detail?name=monterey86.pdf
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-07-31 01:25 -0700 |
| Message-ID | <3ba9a9fa-5088-49a1-a6c0-f8360db1ebd8@googlegroups.com> |
| In reply to | #1533 |
On Wednesday, July 31, 2013 2:56:39 AM UTC-5, luser- -droog wrote:
> On Wednesday, July 31, 2013 2:29:37 AM UTC-5, Cecil Westerhof wrote:
>
> > I am using postscript to generate quotes with borders. For example at:
>
> > https://www.facebook.com/CecilWesterhof
> > There are severall functions you need:
>
> > - drawing the actual border
> > - getting the height of the border
> > - getting the width of the left element
> > - getting the width of the right element
> > - getting the width of the center elements
> >
> > Is there a (best) way that I can work like I am having classes? I just
> > make an assignment of the type of the border I want to use, and the
> > calls give the values belonging to that border.
>
> For the simpler uses of Object-orientation
> (abstraction, encapsulation), you can use dictionaries
> for classes and objects.
>
> Here's a very simple example of an encapsulated turtle:
>
> http://stackoverflow.com/a/8624246/733077
>
> And for serious OO in PS, this is the only Prior Work I've
>
> found, but the code needs modification since it uses non-standard operators:
>
> http://code.google.com/p/xpost/downloads/detail?name=monterey86.pdf
For data-hiding, remember you can set access permissions
on a per-object basis, except for dictionaries.
So you can't do this:
/obj <<
/data9 null
/data1 null
>> def
obj begin
/method0 { //obj /data0 get ... } def
/method1 { //obj /data1 37 put ... } def
end
/obj obj readonly def
Because the readonly applies to the shared dictionary
as a whole. So you'd have to stuff your data into an
array, where you can have multiple handles with different
access. Something more like this:
/obj <<
/private [
<<
/data0 null
/data1 null
>>
]
>> def
obj begin
/method0 {//private 0 get /data0 get ... } def
/method1 {//private 0 get /data1 37 put ... } def
end
obj /private 2 copy get readonly put
Now
obj /private get
will throw an error. But the methods grabbed the
array object before the access was changed (first
in the array object on the stack, and then in the
array object keyed /private in the obj dict),
and so the array objects embedded in the procedures
still have full access.
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-07-31 01:28 -0700 |
| Message-ID | <f54be179-08e9-48c5-a09f-48c35c3f1561@googlegroups.com> |
| In reply to | #1534 |
On Wednesday, July 31, 2013 3:25:18 AM UTC-5, luser- -droog wrote:
>
> Because the readonly applies to the shared dictionary
> as a whole. So you'd have to stuff your data into an
> array, where you can have multiple handles with different
> access. Something more like this:
>
> /obj <<
> /private [
> <<
> /data0 null
> /data1 null
> >>
> ]
> >> def
>
> obj begin
> /method0 {//private 0 get /data0 get ... } def
> /method1 {//private 0 get /data1 37 put ... } def
> end
>
> obj /private 2 copy get readonly put
>
> Now
> obj /private get
0 get % <-- using the array, that is!
> will throw an error. But the methods grabbed the
> array object before the access was changed (first
> in the array object on the stack, and then in the
> array object keyed /private in the obj dict),
> and so the array objects embedded in the procedures
> still have full access.
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-08-01 01:58 -0700 |
| Message-ID | <0626b505-b2e3-47d9-8753-47fecd2569db@googlegroups.com> |
| In reply to | #1534 |
On Wednesday, July 31, 2013 3:25:18 AM UTC-5, luser- -droog wrote:
> On Wednesday, July 31, 2013 2:56:39 AM UTC-5, luser- -droog wrote:
>
> > On Wednesday, July 31, 2013 2:29:37 AM UTC-5, Cecil Westerhof wrote:
>
> > > I am using postscript to generate quotes with borders. For example at:
>
> > > https://www.facebook.com/CecilWesterhof
>
> > > There are severall functions you need:
> >
> > > - drawing the actual border
> > > - getting the height of the border
> > > - getting the width of the left element
> > > - getting the width of the right element
> > > - getting the width of the center elements
> > >
> > > Is there a (best) way that I can work like I am having classes? I just
> > > make an assignment of the type of the border I want to use, and the
> > > calls give the values belonging to that border.
>
> > For the simpler uses of Object-orientation
> > (abstraction, encapsulation), you can use dictionaries
> > for classes and objects.
> >
> > Here's a very simple example of an encapsulated turtle:
> >
> > http://stackoverflow.com/a/8624246/733077
> >
> > And for serious OO in PS, this is the only Prior Work I've
> >
> > found, but the code needs modification since it uses non-standard operators:
> >
> > http://code.google.com/p/xpost/downloads/detail?name=monterey86.pdf
>
[Revised version of previous post.]
For data-hiding, remember you can set access permissions
on a per-object basis, except for dictionaries.
So you can't do this:
/obj <<
/private <<
/data9 null
/data1 null
>>
>> def
obj begin
/method0 { //obj /data0 get ... } def
/method1 { //obj /data1 37 put ... } def
end
obj /private 2 copy get readonly put
Because the readonly applies to the shared dictionary
as a whole. So you'd have to stuff your data into an
array, where you can have multiple handles with different
access. Something more like this:
/obj <<
/private [
<<
/data0 null
/data1 null
>>
]
>> def
obj begin
/method0 {//private 0 get /data0 get ... } def
/method1 {//private 0 get /data1 37 put ... } def
end
obj /private 2 copy get readonly put
Now
obj /private get
0 get
will throw an error. But the methods grabbed the
array object before the access was changed (first
>
> in the array object on the stack, and then in the
>
> array object keyed /private in the obj dict),
>
> and so the array objects embedded in the procedures
>
> still have full access.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web