I have a bunch of subclasses of ItemViewModels (to...
# getting-started
j
I have a bunch of subclasses of ItemViewModels (tornadofx) that all have the same function that returns an entitysequence from a db. Is there a way to have a function that accepts a generic(my ItemViewModel subclasses) and call the appropriate subclass.getSequence() and return the entitysequence? It seems like this is possible but I'm having a hard time deciphering how
j
If they all have the same function, you can declare that function in an interface, and make them all implement that interface. Then you can declare a function that accepts that interface
c
How new are you to the concept of interfaces and polymorphism in general?
j
I understand interfaces at a basic level. In fact I thought to use a interface with a declared function But the function getSequence in all my sub-classes is so similar it doesn't feel DRY and because it feels redudant I may be trying to overthink the situation beyond my level.
j
If you can share a little bit of code maybe we can help you more precisely
j
https://pastebin.com/nDZM8xGf this is what I have, what I need is a way to take a selected project, call the database and returns an ObservableList of said type submittals,RFIs,PCOs,COs
that has to be bound to the itemviewmodel so my UI will updated
what I've been doing is creating a new instance of said data class and populating it with the returned database call and then rebinding the model to the new instance https://pastebin.com/DG2r72L1
and this is where it just doesn't feel right to me, i'm repeating myself and it looks ugly
j
wow there were so many ads on pastepin I had trouble finding the code in the middle 😆 you can also use the Kotlin playground (play.kotlinlang.org) if you want to share and run code. About your problem, I'm sorry but I have trouble understanding how your code fits together here. For instance, I don't see where the
bindModel
functions from the second pastebin are declared, nor where the called `model.getRFIs`/`getPCOs` etc are declared, and how they are implemented. So it's a bit difficult to help without the whole picture
j
I've pushed to github. You can see the entire project there. The link below is where I'm having difficulty figuring out my best course of action. https://github.com/jasin/Cobis/blob/master/src/main/kotlin/com/coleburt/cobis/controllers/NavigationController.kt
in the Nav Controller I am repeating a lot of code that is very similar. I will also need this similar code in my editor controller as well so when a submittal/RFI/PCO/CO is changed I can update the itemviewmodel. It seems to me there should be a better way to accomplish this repetitive task of accessing the DB after the DB has been updated to update my UI.
Sorry that I can't more precisely illistrate the issue.