Tiddlywiki Object-oriented and method overriden

55 views
Skip to first unread message

Mohammad

unread,
Jan 23, 2020, 1:38:00 AM1/23/20
to tiddl...@googlegroups.com
From: https://en.wikipedia.org/wiki/Method_overriding

Assume you have a tiddler called Parent with the below contents

\define a() This is a
\define b() This is b
\define main()
<<a>>. <<b>>
\end


Now in tiddler01 do as below

\import [[Parent]]
<<main>>


After saving it will display
This is a. This is b


and in tiddler02 do as below

\import [[Parent]]
\define a() This is NEW a
<<main>>


After saving it will display

This is NEW a. This is b


So, you can simply override the method a (in Tiddlywiki macro a).

What do you think?

--Mohammad

TonyM

unread,
Jan 23, 2020, 2:13:58 AM1/23/20
to tiddl...@googlegroups.com
Mohammad,

[minor edit]

Yes this is useful, some tricky things can be done with this, I would suggest documenting this in your wiki text when you use it, or you could come undone. Such that elsewhere in your wiki when you depend on the value from Parent.

We could call this "[re]\define"

One idea is to name the macro in a way where you know it may be overridden eg current-a would suggest there is a value set in parent but you may override it in the current tiddler with \define current-a.

When I write macros I try and place them in global macros and view templates etc... rather than include them in the working tiddlers that contain my information. In this case it can sometimes be hard to evaluate which define is likely to win, but you can count on the current tiddler having the known value if it contains the define.

Here is a similar example, tagged macros 
\define a() {{$:/config/global-a}}

Then in a tiddler "a" returns the content of $:/config/global-a as the value

But these as you have done in your example the local tiddler can have
\define a() not-global-a <!--override global"a"-->

<<a>>

Another way is just inside a macro with set/vars etc...
\define test()
<<a>> <!-- uses global a -->
\end
\define test-2()
<$set name=a value="local value">
<<a>> <!-- uses local a -->
</$set>
\end

Regards
Tony

Mohammad

unread,
Jan 23, 2020, 2:24:39 AM1/23/20
to TiddlyWiki
Hi Tony!
Many thanks for your feedback.

Actually I try to see how OOP can be implemented using TW.

So, I used the oop terminology! But you are right TW users should know
what equivalents are those terms in TW.

Thank you
Mohammad

TiddlyTweeter

unread,
Jan 23, 2020, 4:23:28 AM1/23/20
to TiddlyWiki
Ciao Mohammad

I think what is interesting is you are bringing out how you can use "\define" cascade order intelligently to reduce code redundancy and leverage function.

In a way it is obvious--more experienced users use it already implicitly. 
But I think an explicit more formal approach could be very helpful! 

It would be interesting to see a more complex example. As TonyM commented, I think you'd need a methodology to keep track of it. 

Best wishes
TT 

Mohammad

unread,
Jan 23, 2020, 4:56:34 AM1/23/20
to TiddlyWiki
I will Josiah!

I am working on a wiki to document the possible OOP in Tiddlywiki using KISS principle.

--Mohammad
Reply all
Reply to author
Forward
0 new messages