December 2016
Intermediate to advanced
841 pages
17h
English
In the previous chapter, we saw how to work with generic functions. We will now take a look at how to work with generic classes.
Just like with generic functions, generic classes can help us to avoid the duplication of code. Let's take a look at an example:
class User {
public name : string;
public password : string;
}This example is included in the companion source code.
We have declared a User class, which contains two properties: name and password. We will now declare a class named NotGenericUserRepository without using generics. This class takes a URL via its constructor and has a method named getAsync. The getAsync method will request a list of users stored in a JSON file using AJAX:
class NotGenericUserRepository { private ...Read now
Unlock full access