Program with Xojo from scratch: collections, dictionaries ... and class builder

Program with Xojo from scratch: collections, dictionaries ... and class builder

We continue with the Development Course with Xojo (from scratch), and in this case we continue to see the elements of the programming language that allow us to work with data collections.

We changed our sample application (Personal Spending Tracking) to use dictionaries rather than just arrays, allowing us to continue spending by categories.

After all, you can think of a dictionary as an advanced array where we can assign a value (any kind of value) to a certain key. So instead of using indexes (an integer value) to access a specific value, as we would do when using Arrays, in Dictionaries we will use the value we previously assigned as a class.



Also, the key value is not limited to primary data types (integers or strings, for example) but can be absolutely any class instance. Added to the fact that we can also assign any type of data as a key value… you can get an idea of ​​the power and flexibility this represents.

Another advantage of dictionaries over arrays is that you won't need to go through (or iterate) them to find or access an associated value. It is the advantage of using a key (or key) for this.

Applied to the program we are developing throughout the chapter, this flexibility is what will allow us to create a Dictionary where we will use the category value as a key, assigning as a value all the expenses corresponding to that category.

Class builders

And from the point of view of Object Oriented Programming, in this chapter we will also begin to see a very particular method: the Constructor.


In a simplified way, this is the method that will be executed every time we create a new instance (or object) from a certain class; so it is extremely useful for initializing the object from values ​​received as arguments.



You will see how throughout the video, where with a simple invocation in the creation of a new object, it will no longer be necessary to subsequently and individually access each of the properties of the Expense instance to assign the values ​​entered by the user.


As usual, I recommend that you review all of these concepts in the Xojo documentation. Thus, you will be able to see all the methods you can use with Dictionary instances (Dictionary class) and also the possibilities that the Constructor method offers you when designing your own classes.

add a comment of Program with Xojo from scratch: collections, dictionaries ... and class builder
Comment sent successfully! We will review it in the next few hours.