-
Notifications
You must be signed in to change notification settings - Fork 0
Exercise 2 - Json, Polymorphism, List #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: exercise-2-poli
Are you sure you want to change the base?
Conversation
…re as classes Restaurants e CoffeeShop, usando o conceito de polimorfismo para resolver o problema. Criei também uma função prettyPrint que verifica qual classe é, e exibi na tela conforme pedido.
|
|
||
| open class CommercialPlace( | ||
| val name: String, | ||
| val address: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address não é um objeto?
|
|
||
| val gson = Gson() | ||
|
|
||
| open class CommercialPlace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pq não usou uma Interface ou abstract Class? Dá uma estudada nisso
| fun prettyPrint(commercialPlace: List<CommercialPlace>) { | ||
| commercialPlace.forEach { commercialPlace -> | ||
| when (commercialPlace) { | ||
| is CoffeeShop -> println("Name: ${commercialPlace.name}, Rating: ${commercialPlace.rating}, Address: ${commercialPlace.address}") | ||
| is Restaurants -> println("Name: ${commercialPlace.name}, Address: ${commercialPlace.address} Rating: ${commercialPlace.rating},") | ||
| } | ||
|
|
||
| println() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essa função faz parte de alguma classe? Não... isso não é assim, estuda mais polimorfismo
| val json = jsonFile.readText() | ||
| //val listType = object : TypeToken<List<CommercialPlace>>() {}.type | ||
| //val commercialPlace: List<CommercialPlace> = gson.fromJson(json, listType) | ||
| val commercialPlace: List<CommercialPlace> = Gson().fromJson(json, Array<CommercialPlace>::class.java).toList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como que vc sabe que um ComercialPlace é café ou restaurante no Json? Não estou vendo nada no jSon me contando isso.
Customized function to receive Restaurants and Cafeterias and print them, using the concept of polymorphism.