Exercise: Blog Post Properties
In your project, you're working with a BlogPost
class that represents a blog post, including its title, content, and author details. Your task is to enhance the BlogPost
class by adding and implementing the following properties:
authorName
- a string that combines the author's name and surname. For example, if the author's name is "John" and the surname is "Smith", the value of this property should be "John Smith". You can assume that you will need to use this property many times per blog post object.wordCount
- an integer that represents the number of words in the blog post. You can assume that this property is expensive to calculate and you might need it more than once per blog post objectisLongRead
- a boolean that indicates whether the blog post is longer than 1000 characters. You can assume that you will need to use this property at most once per blog post object.summary
- a string that is calculated using thegenerateSummary
function. This object is very heavy to calculate, so you don’t want to calculate it more than once.
You need to decide how to implement each of these properties. Your options are:
- A
val
property defined by a value - A
val
property defined by a getter - A lazy property
Starting code:
This problem can either be solved in the below playground or you can clone kotlin-exercises project and solve it locally. In the project, you can find code template for this exercise in advanced/delegates/Lazy.kt. You can find there starting code.
Once you are done with the exercise, you can check your solution here.