[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cached queries
From: |
Eric Bezault |
Subject: |
Re: Cached queries |
Date: |
Mon, 8 Jan 2024 07:58:31 +0100 |
User-agent: |
Mozilla Thunderbird |
On 07/01/2024 23:41, Paolo Redaelli wrote:
I found myself using this pattern over and over again:
|class FOO|
|feature {ANY}|
| costly_query: SOMETHING is|
| do|
| if cached_costly_query=Void then compute_costly_query end|
| Result := cached_costly_query|
| end|
|feature {} -- Implementation|
| cached_costly_query: like costly_query|
| compute_costly_query is|
| do|
| -- ......|
| ensure cached_costly_query/=Void|
| end|
|end|
Do you know of a more "precanned" / more elegant / better way of doing it?
In ECMA Eiffel (attached mode) you can write:
costly_query: SOMETHING
attribute
Result := -- costly computation
ensure
costly_query_not_void: Result /= Void
end
Otherwise, if `costly_query' is never modified, you can use
a once-per-object:
costly_query: SOMETHING
once ("OBJECT")
Result := -- costly computation
ensure
costly_query_not_void: Result /= Void
end
I don't know whether these are supported in Liberty.
They are in ISE Eiffel and Gobo Eiffel.
--
Eric Bezault
mailto:ericb@gobosoft.com
http://www.gobosoft.com
- Cached queries, Paolo Redaelli, 2024/01/07
- Re: Cached queries,
Eric Bezault <=