Ecere SDK/eC Forums https://ec-lang.org/community/ Print view |
|
Multi inheritance or interface in eC https://ec-lang.org/community/viewtopic.php?f=1&t=209 |
Page 1 of 2 |
Author: | samsam598 [ Thu Jan 12, 2012 7:26 pm ] |
Post subject: | Multi inheritance or interface in eC |
Greetings, I was wondering how does eC implement the subjected in the language? Given below code in C++ and C#,how does eC implement the same function in class Car? Thanks for the help in advance. C++: Code: Select all
Code: Select all
|
Author: | jerome [ Sun Jan 15, 2012 12:12 am ] |
Post subject: | Re: Multi inheritance or interface in eC |
Hi Sam, Sadly, eC does not have multiple inheritance, and does not have interfaces. Multiple inheritance is a pain to implement, because you end up with a different offset for the class data members depending on which derived class you're dealing with. Given the way the eC compiler and runtime component is set up, this would not be impossible to implement, but it's currently not on my personal wishlist (which contains a lot of stuff compared the amount of time available to implement them ). Interfaces are indeed a nice alternative to multiple inheritance, which Java and C# went with. I never really programmed with them, although I did try to understand how they work and what you can do with them. I still don't have a firm grasp of how they are used and I am still unsure whether eC needs them or how to go about adding interface support in eC. Your Car/Engine/Wheel does not do enough for me to see the problem you're trying to solve, and thus how you could solve it using the tools that eC already have available... For example, you do not have any virtual methods in there, and I'm really not sure how you mean to use the Car, Engine and Wheel classes individually. One feature that eC has is Instance Virtual Methods. You could use this to program some specifics of the Engine and Wheels that are particular to the new class making use of them (the car), by overriding some of the Engine or Wheel's methods in the Car class. In eC it's also possible to tweak the 'this' type to a specific type, or for it to adapt to the enclosing class. This, combined with a 'holder' which would identify the 'Car' from within the Engine/Wheel would let you do something like this: Code: Select all
Another thing which is available in eC is the 'subclass' keyword, which is used to refer to a particular derived class of a specified class. This can be used alongside 'thisless' virtual methods, and an any_object parameter, to be used with any unrelated class. This way you can sort of implement 'interfaces' (which cannot have data members). This supports the '.' member operator for the subclass type to behave like an instance. Here is an example to demonstrate how this can be used: Code: Select all
Please comment whether you would see either of them useful in the interfaces/MI scenarios you had in mind! To sum it up, eC has neither interfaces nor multiple inheritances, but it has some tools that can serve similar purposes. However, there is still room for improvement, and hopefully in the future we will handle these things more elegantly! All the best, Jerome |
Author: | rfc_club [ Tue Sep 17, 2013 11:37 pm ] |
Post subject: | Re: Multi inheritance or interface in eC |
I really hope that eC can support multiple interfaces. Normally it can be treated as a decoupling part when you want to change your implementation in future. Besides it defines the contract when working in team, to make sure that the change in one side do not effect to other side. Take an example: public interface FinancialAccount { void deposit(int amount); int checkout(); } public class AtmAccount : FinancialAccount { // concrete implementation of deposit & checkout } public class BankAccount : FinancialAccount { // concrete implementation of deposit & checkout } public class FinalcialItems { List<FinalcialService> list; } Assume that business logic of each account is differ. eC seems a wonderful language, and it can be more better with interface. Please, I really hop that eC can support it in next release . |
Author: | jerome [ Wed Sep 18, 2013 3:05 am ] |
Post subject: | Re: Multi inheritance or interface in eC |
Thanks for the suggestion rfc_club! Multiple interfaces support would indeed be nice, and they are planned for 0.45 right now: http://ecere.com/mantis/view.php?id=514. It may be a while seems that becomes available, but it's already on the roadmap At the moment you can actually sort of manually implement interfaces, as the previous examples above describes. Here's a slightly different twist using your example: Code: Select all
|
Author: | jerome [ Wed Sep 18, 2013 3:22 am ] |
Post subject: | Re: Multi inheritance or interface in eC |
The equivalent eC code with interfaces support could look something like: Code: Select all
Jerome |
Author: | samsam598 [ Wed Sep 18, 2013 11:20 pm ] |
Post subject: | Re: Multi inheritance or interface in eC |
Could you please consider not adding new key word implements which is sort of VB.net verbos style.In c/c++/eC I prefer : and . pairs. Code: Select all
|
Author: | jerome [ Thu Sep 19, 2013 12:05 am ] |
Post subject: | Re: Multi inheritance or interface in eC |
Sam, The 'implements' was to distinguish interface implementation vs class inheritance... class MyClass : MyBaseClass implements Engine, SafetyFeatures An interface will be defined somewhere else most of the time, so this is to make it obvious. And since interfaces got popular with Java, I'm just following the Java trend =) What do you think? |
Author: | samsam598 [ Tue Oct 01, 2013 11:02 pm ] |
Post subject: | Re: Multi inheritance or interface in eC |
Could IDE help to identify which is a class and which is an interface? Anyway this is a taste choice by one own and I will accept `implements' as well.To my own,I prefer the less key word the better. I will be more than happy and always loving ecere as long as it keeps C's simplicity,purity,real time direct access to hardware and OS;on the contrary,hope there will not be another Java or C++---Having every POWERFUL feature or making everything class and OOP is NOTHING.As I mentioned before,the longer time using eC,I appreciated more the language's beauty. If there is a wish---I hope there will be more visual controls in the designer to drag and drop to the form designer,such as menu editor,tool bar designer and so on;on the language level,hope c99 could be supported to ease the interaction with exsiting third party sources and libraries which may use c99's feathers. Best regards, Sam |
Author: | jerome [ Tue Oct 01, 2013 11:53 pm ] |
Post subject: | Re: Multi inheritance or interface in eC |
The IDE helping to identify which is a class/interface -- We could do that, but eC code is not always going to be looked at or edited in the Ecere IDE One of the design goals of the SDK is that the language, toolkit and IDE should each stand on its own (and inter-operate with others). We're always very happy when people are appreciating our hard work and dedication These goals you mention for the language are all there to stay! The designer hasn't received much attention in a very long time, I was hoping and planning for all these features you're mentioning but there's just too much work right now and too little developers to focus on this. One of the reasons it's lower in priority is that eC is so elegant now that it's quite easy to put together these things and edit them in the code. But I'm still wishing for all that in a later version! C99 -- I think we're slowly working our way up to have C99 compatibliity. Any more work on this though will wait until the compiler re-factoring next year which should make it much easier to support new language features. Cheers, Jerome |
Author: | samsam598 [ Wed Oct 02, 2013 12:50 am ] |
Post subject: | Re: Multi inheritance or interface in eC |
Thanks!Knowing the fact that c++ support too much stuffs finally make itself an extremely complicated language.Trust eC won't be that.But have to say,only C++ in the world can create an object in stack ,not only on the heap. |
All times are UTC-05:00 | Page 1 of 2 |
Powered by phpBB® Forum Software © phpBB Limited |