Question about overrides

Permalink
In Concrete 5 to override you create a class which "extends" the concrete classes.

IKn this articlehttp://www.concrete5.org/documentation/how-tos/developers/overridin... it states.

"Remember, when overriding a file in concrete5 the original file is never included and therefore, as in this case, any class definitions in that file will never occur."

So does this mean you have to copy the whole class across and make your alterations / extensions?

Or can you just override / add methods?

To me it seems if anything changes in the core class the developer would then have to redo this override if the core file is modified. In any case is my assumption correct that the whole core file should be copied into the extended version
?

 
JohntheFish replied on at Permalink Reply
JohntheFish
The article predates the override mechanism you are using. All of it is accurate, apart from it predating being able to extend concrete classes and thus no longer needing to define everything in the original class. The concrete class mechanism was added to overcome that limitation.
michaelDotco replied on at Permalink Reply
So in other words, you are able to modify / extend methods and not have to define all the other methods in the class if you are not overriding them?

Thanks.
JohntheFish replied on at Permalink Reply
JohntheFish
As long as you extend the concrete class - yes.
michaelDotco replied on at Permalink Reply
It is strange though as when I tried to extend a core library class I tested it by just overriding one method and the site broke. I then overrode the class with the other methods of the original class and the site started working.

I think I will leave them in there just to be on the safe side. However I think this approach is less maintainable in the long run.
JohntheFish replied on at Permalink Reply
JohntheFish
Did you override the wrapper class, or were you overriding the actual concrete core class?

If you just copy the declaration of the wrapper class into the appropriate override location and add just the methods you want to override to it, that is basically all you need to do.

There is an easy trap to fall into with models where there are often static methods to instantiate objects of the class, in which case you need to instantiate an object of your class, not the concrete class.