Can a changed property be inherited when extending...
# cfml-beginners
Can a changed property be inherited when extending a component? I know the default property values can be get/set using accessors, but let's say I have a component that takes in several arguments when initialized. Then based on these different inputs several sub components are then initialized that extend the first. So rather than adding several repeated lines of arguments when initializing these sub-components, can they essentially just extend a particular instance of the parent component? Hopefully that made sense
No, sorry, that doesn't make sense 🙂
A class doesn't extend an "instance" of another class. it extends the class definition.
I'm also not entirely sure what you mean by "changed property"
A CFC "property", strictly speaking, is set at compile time and defined by a
Copy code
component {
  property name="foo";
  property name="bar";

has two properties and will always have two properties.
Now, you can set arbitrary variables inside the CFC into the
scope, but that won't add "properties" per se as far as the metadata of the CFC is concerned.
I know you are writing an example, but your description sounds like you want 2 cfcs. 1 the object that holds the logic and 2 a builder or factory that builds the object with the correct internal values.
If you're just trying to prevent the overhead of initializing a handful of composed CFC instances across your model, I'd look into some other approaches and put some thought into the OO design here and what classes should be composed of what other classes.
If the CFC instances you're trying to share are utilities or singletons, then this is an issue DI frameworks help solve (providing the singleton scope and injections) for you.
@deactivateduser exactly
Its sounds like your'e trying to treat CF like it's Java perhaps. That's more of a Java design pattern IMO to have a static method that creates instances.
Either way, my recommendation of looking at an object factory like WireBox still stands.
Then I agree with Brad, you probably want to first try to fit into your existing DI framework, if they don't support your exact scenario. Which I have a similar one, then I would create a singleton factory or builder object that creates instances of whatever you need when you need it. It really depends on the level of persistence you need with these "built" objects
@bdw429s thanks for all the replies, I will start looking in that direction. Does wirebox work well with a cfwheels app?
I would actually expect CFWheels to already have a solution for this, but I'm not super familiar with it
but yes, WireBox can be instantiated standalone anywhere. I THINK there's a CFWheels channel floating around this slack
CFWheels doesn't do OOP concepts very well.
Or MVC web application concepts either for that matter.
Sweet, thanks for the help @bdw429s
I recently managed to get DI/1 wired into CFWheels, and documented it here; It'll be largely the same process for WB
❤️ 2
@Adam Cameron I'll take a look
Yea youll probably be shoe horning there..... it is possible to use wirebox. If this is the only current instance you need I would potentially just go custom builder object and try to slowly move into one of the proper di libraries.
Oh and there's a chapter 2 cos chapter 1 got too long...
@jumpmaster ping me if you need anything clarified.
Will do