個this唔同
Let say 而家object a既method 1 forward/delegate比object b既method 2
Forward黎講 個this係b
delegate黎講 個this係a 所以可以access a既protected member/method
労働はクン2022-05-31 09:11:05
有冇人聽過argyll scott?
收到封email入面有堆2HBU+ dev位,似唔似呃CV?
好似有D too good to be true
媽咪做社工2022-05-31 09:21:22
You cannot really control whether the language is a delegate one or a forwarding one.
But you can control how the (child) class behaves differently, according to the caller, without using this.
手一黏便緊(UTC+92022-05-31 09:31:06
There are real consequence of using this, namely protected method/member.
There is stupid hack to use delegation: virtual delegatee method in delegator class, and delegatee derives from delegator so that it can access protected member/method.
A much better way is using friend, eg
class delegatee_base;
class delegator{
friend class delegatee_base;
};
and pass the delegator reference to every delegatee method call. Does not have the syntax sugar of “this”, but I think the syntax sugar is not preferred anyway.
腦若傷殘2022-05-31 09:31:54
媽咪做社工2022-05-31 09:40:48
That's a good explanation for friend class.
仆街,比我抖吓啦2022-05-31 10:59:12
仆街,比我抖吓啦2022-05-31 10:59:52
靈幻新隆2022-05-31 12:14:54
屌那星公司諗住請件nmsl
手一黏便緊(UTC+92022-05-31 12:26:52
Oh gosh I totally forget the stupid language running on billions devices!
Seriously, if Java can be good at one thing, I hope it is garbage collecting and collect itself.
飲水教父2022-05-31 12:32:00
Sad but sad
媽咪做社工2022-05-31 12:33:05
所以咪可以用delegate by inheritance with virtual function 做workaround
雖然咁有啲唔OO
手一黏便緊(UTC+92022-05-31 12:50:07
Tell me more on how Java prevent null pointer exception
Java: less potential, done almost nothing on preventing the most common problem
手一黏便緊(UTC+92022-05-31 12:56:31
And I guess people forget about pascal, Delphi, basic, Visual Basic, qt... when they talk about how Java lower the barrier of writing software quickly.
Java succeeded only because of Netscape supporting applet, not because of being great in software development (hint: it’s not).
手一黏便緊(UTC+92022-05-31 13:00:09
To be clear: I am not saying C++ is great; it’s not especially for most of the modern parts.
The issue is, Java especially sucks, and officially advertise itself as great.
手一黏便緊(UTC+92022-05-31 13:09:15
As I mentioned C++, let’s talk about how traditional C++ sucks.
Stream. WTF.
Luckily there is alternative.
This teaches me one thing: every design will suck in a way you don’t expect. Provide convent alternatives to your users, instead of making alternatives hard or impossible.
手一黏便緊(UTC+92022-05-31 13:13:19
Can’t reach an agreement.
And btw, ppl get job done, not language. If work quality is bad in C++ for some cheap labor, work quality will be bad in Java too.