Scala Wrapper class by extending Component and with the SequentialContainer.Wrapper trait, do I have the correct understanding of traits? - swing

The following code was taken from this post: How to create Scala swing wrapper classes with SuperMixin?
import scala.swing._
import javax.swing.JPopupMenu
class PopupMenu extends Component with SequentialContainer.Wrapper {
override lazy val peer: JPopupMenu = new JPopupMenu with SuperMixin
def show(invoker: Component, x: Int, y: Int): Unit = peer.show(invoker.peer, x, y)
}
I've been trying to make custom wrappers so need to understand this, which is simple enough but since
I'm only starting to get acquainted with Scala so I'm a little unsure about traits. So what I've been hearing is that traits is like multiple inheritance and you can mix and match them?
I've drawn a diagram representing where PopupMenu sits within the whole inheritance structure. Just to clarify a few things:
1) It seems to override lazy val peer:JComponent from Component and also gets the contents property from SequentialContainer.Wrapper? (purple text) Is that right?
2) Sequential.Wrapper also has a abstract def peer: JComponent.. but this isn't the one being overriden, so it isn't used at all here?
3) What's confusing is that Component and Sequential.Wrapper have some identical properties: both of them have def publish and def subscribe (red text).. but the one that the popupMenu will use is subscribe/publish from the Component class?
4) why can't we write PopupMenu extends SequentialContainer.Wrapper with Component instead?
Hopefully that isn't too many questions at once. Help would be much appreciated, I'm a beginner to Scala..

I'll answer using the numbers of your questions:
Correct
Correct. The top trait is UIElement which defines an abstract member def peer: java.awt.Component. Then you have Container which merely adds abstract member def contents: Seq[Component] to be able to read the child components. Container.Wrapper is a concrete implementation of Container which assumes (abstractly) the Java peer is a javax.swing.JComponent. Note that in Java's own hierarchy, javax.swing.JComponent is a sub-type of java.awt.Component, so there is no conflict. Sub-types can refine the types of their members ("covariance"). SequentialContainer refines Container by saying that contents is a mutable buffer (instead of the read-only sequence). Consequently, its implementation SequentialContainer.Wrapper mixes in Container.Wrapper but replaces the contents by a standard Scala buffer. At no point has a concrete peer been given, yet. For convenience, Component does implement that member, but then as you have seen, the final class PopupMenu overrides the peer. Because of the way the type system works, all the participating traits can access peer, but only PopupMenu "knows" that the type has been refined to be javax.swing.JPopupMenu. For example SequentialContainer.Wrapper only knows there is a javax.swing.JComponent, and so it can use this part of the API of the peer.
The Publisher trait is introduced by UIElement, so you will find it in all types deriving from UIElement. There is nothing wrong with having the same trait appear multiple times in the hierarchy. In the final class, there is only one instance of Publisher, there do not exist multiple "versions" of it. Even if Publisher had not been defined at the root, but independently in for example Component and SequentialContainer.Wrapper, you would only get one instance in the final class.
This is an easy one. In Scala you can only extend one class, but mix in any number of traits. Component is a class while all other things else are traits. It's class A extends <trait-or-class> with <trait> with <trait> ....
To sum up, all GUI elements inherit from trait UIElement which is backed up by a java.awt.Component. Elements which have child elements use trait Container, and all the normal panel type elements which allow you to add and remove elements in a specific order use SequentialContainer. (Not all panels have a sequential order, for example BorderPanel does not). These are abstract interfaces, to get all the necessary implementations, you have the .Wrapper types. Finally to get a useable class, you have Component which extends UIElement and requires that the peer is javax.swing.JComponent, so it can implement all the standard functionality.
When you implement a new wrapper, you usually use Component and refine the peer type so that you can access the specific functionality of that peer (e.g. the show method of JPopupMenu).

Related

kotlin, how to simplify passing parameters to base class constructor?

We have a package that we are looking to convert to kotlin from python in order to then be able to migrate systems using that package.
Within the package there are a set of classes that are all variants, or 'flavours' of a common base class.
Most of the code is in the base class which has a significant number of optional parameters. So consider:
open class BaseTree(val height:Int=10,val roots:Boolean=true, //...... lots more!!
class FruitTree(val fruitSize, height:Int=10, roots:Boolean=true,
// now need all possible parameters for any possible instance
):BaseTree(height=height, roots=roots //... yet another variation of same list
The code is not actually trees, I just thought this was a simple way to convey the idea. There are about 20 parameters to the base class, and around 10 subclasses, and each subclass effectively needs to repeat the same two variations of the parameter list from the base class. A real nightmare if the parameter list ever changes!
Those from a Java background may comment "20 parameters is too many", may miss that this is optional parameters, the language features which impacts this aspect of design. 20 required parameters would be crazy, but 10 or even 20 optional parameters is not so uncommon, check sqlalchemy Table for example.
In python, you to call a base class constructor you can have:
def __init__(self, special, *args, **kwargs):
super().__init(*args, **kwargs) # pass all parameters except special to base constructor
Does anyone know a technique, using a different method (perhaps using interfaces or something?) to avoid repeating this parameter list over and over for each subclass?
There is no design pattern to simplify this use case.
Best solution: Refactor the code to use a more Java like approach: using properties in place of optional parameters.
Use case explained: A widely used class or method having numerous optional parameters is simply not practical in Java, and kotlin is most evolved as way of making java code better. A python class with 5 optional parameters, translated to Java with no optional parameters, could have 5! ( and 5 factorial is 60) different Java signatures...in other words a mess.
Obviously no object should routinely be instanced with a huge parameter list, so normall python classes only evolve for classes when the majority of calls do not need to specify these optional parameters, and the optional parameters are for the exception cases. The actual use case here is the implementation of a large number of optional parameters, where it should be very rare for any individual object to be instanced using more than 3 of the optional parameter. So a class with 10 optional parameters that is used 500 times in an application, would still expect 3 of the optional parameters to be the maximum ever used in one instance. But this is simply a design approach not workable in Java, no matter how often the class is reused.
In Java, functions do hot have optional parameters, which means this case where an object is instanced in this way in a Java library simply could never happen.
Consider an object with one mandatory instance parameter, and five possible options. In Java these options would each be properties able to be set by setters, and objects would then be instanced, and the setter(s) called for setting any relevant option, but infrequently required change to the default value for that option.
The downside is that these options cannot be set from the constructor and remain immutable, but the resultant code reduces the optional parameters.
Another approach is to have a group of less 'swiss army knife' objects, with a set of specialised tools replacing the one do-it-all tool, even when the code could be seen as just slightly different nuances of the same theme.
Despite the support for Optional parameters in kotlin, The inheritance structure in kotlin is not yet optimised for heavier use of this feature.
You can skip the name like BaseTree(height, roots) by put the variable in order but you cannot do things like Python because Python is dynamic language.
It is normal that Java have to pass the variables to super class too.
FruitTree(int fruitSize, int height, boolean root) {
super(height, root);
}
There are about 20 parameters to the base class, and around 10 subclasses
This is most likely a problem of your classes design.
Reading your question I started to experiment myself and this is what I came up with:
interface TreeProperties {
val height: Int
val roots: Boolean
}
interface FruitTreeProperties: TreeProperties {
val fruitSize: Int
}
fun treeProps(height: Int = 10, roots: Boolean = true) = object : TreeProperties {
override val height = height
override val roots = roots
}
fun TreeProperties.toFruitProperty(fruitSize: Int): FruitTreeProperties = object: FruitTreeProperties, TreeProperties by this {
override val fruitSize = fruitSize
}
open class BaseTree(val props: TreeProperties)
open class FruitTree(props: FruitTreeProperties): BaseTree(props)
fun main(args: Array<String>){
val largTree = FruitTree(treeProps(height = 15).toFruitProperty(fruitSize = 5))
val rootlessTree = BaseTree(treeProps(roots = false))
}
Basically I define the parameters in an interface and extend the interface for sub-classes using the delegate pattern. For convenience I added functions to generate instances of those interface which also use default parameters.
I think this achieves the goal of repeating parameter lists quite nicely but also has its own overhead. Not sure if it is worth it.
If your subclass really has that many parameters in the constructur -> No way around that. You need to pass them all.
But (mostly) it's no good sign, that a constructor/function has that many parameters...
You are not alone on this. That is already discussed on the gradle-slack channel. Maybe in the future, we will get compiler-help on this, but for now, you need to pass the arguments yourself.

get/set methods and constructors in class diagram

recently I was assigned to develop an use case diagram and a class diagram for a conference management system. First I developed use case diagram and then class diagram. In the class diagram I have the following unclear parts:
Do we need to show get and set methods for all the private fields in every class. Or we can omit get and set methods, since it is obvious.
Do we need to show the constructors in a class? If it is not necessary, what is the reason for not showing them? I have seen lot of class diagrams without the constructors but the reason for that is beyond my understanding.
Gets and sets methods are not UML definition. It is just way how to manipulate with attribute values in some programming languages. Pure UML know attribute , its type, name and other properties.
Typical usage of getters and setters in programing is to implement readonly or derived (calculated) attributes.
You do not have to define getters and setters in uml class diagram.
Constructor:
You can define constructor operation in class of course. Constructor operation has keyword "create" at the beginning of its name. You can assign behavior definition to constructor as its method to define how to construct instance of class.
See Common Behavion in UML Superstructure.

Why do some languages have metaclasses?

I see Java has only one metaclass (the Class class), but other languages, say Smalltalk, have one metaclass for each Class.
Why is that? What's the need for metaclasses? What difference does it make to have them one way or another?
The fundamental need for at least one metaclass is that if you want objects that represent classes (or want classes to be objects), then those objects must have a type.
Wikipedia says:
In early Smalltalks, there was only one metaclass called Class. This
implied that the methods all classes have were the same, in particular
the method to create new objects, i.e., new. To allow classes to have
their own methods and their own instance variables (called class
instance variables and should not be confused with class variables),
Smalltalk-80 introduced for each class C their own metaclass C class.
So the question is, do you want every class object to have the same type (and hence the same members), or do you want class objects to differ in ways that require them to have different types, so that there are type-checked operations which can be performed on the object that represents class A but not on the object that represents class B? Java and early Smalltalks answered that question differently from later Smalltalks.
So for example java.lang.Class.newInstance() takes no constructor arguments, whereas you can imagine that it might be nice to be able to call clz.newInstance(1) where clz is the class object for a class that has a constructor with takes an int. In Java you can still look through the constructors of the class yourself to find a match for the arguments you want to pass, but the type of the class object doesn't tell you whether you will find one.
Also note that Smalltalk stops at one level. The type of C is C class, but the type of C class is Metaclass. There's no infinite recursion of types C class class etc, because although different class objects in Smalltalk accept different messages, there's no demand for different metaclass objects to accept different messages.

Abstract in programming

The word abstract is when we talk about a queue class or any class. A class is abstract right? How's the word abstract used in programming. Somehing that is abstract? What does that mean?
Abstract in OO is used to indicate that the class cannot be instantiated directly and must be inherited from before instantiation. Wiki explains this nicely.
Abstract means that you are discussing an idea one or more levels away from any specific example that you can actually point to or create.
As far as classes are concerned, an abstract class is abstract because it can't be instantiated. A specific class that can be instantiated is concrete, and it may be an example of a certain abstract class.
Similarly, if your data structures class discusses an 'abstract' data type such as a Queue, the teacher means Queue as 'a FIFO data structure'. Slightly less absract is Java's AbstractQueue. A concrete queue that you can "point to" (not in the sense of pointers and memory, but in the sense "THERE is a queue!") could be Java's LinkedBlockingQueue
`Abstract` ... ... ... ... ... ... ... ... ... `Concrete`
a queue AbstractQueue LinkedBlockingQueue
a group an infinite group positive integers
a car a Ford 1995 Ford Taurus My 1995 Ford Taurus VIN# 3489230148230
The term "abstract" can mean a whole bunch of different things, depending on the context.
The two most common uses of "abstract" pertain to object-oriented programming. A method is called "abstract" (or, in C++-speak, "pure virtual") if the method does not have an implementation. The purpose of an abstract method is to indicate that classes that inherit from the given class will all have a method with the given signature, but there is no reasonable default behavior for that method. A common example is, in a class hierarchy of shapes, that the base class for shapes might have an abstract method that draws the shape on the screen. There is no good default behavior for drawing "a shape" - what shape it it? - but any individual shape will have a concrete implementation of this function.
A related term is an "abstract class," which is a class that contains an abstract method. Because the class contains this abstract method, you can't have a concrete object of that class type. Otherwise, if you tried calling the abstract method, you'd find out that there was no implementation associated with it.
In an entire different context, the word "abstract" sometimes shows up in the term "abstract data type," which is a term used to describe an object supporting some set of mathematical operations without necessarily explaining how those operations are implemented. For example, "stack," "queue," and "list" are all abstract data types, since they describe what behaviors are expected of a given type of object without giving implementation (e.g. dynamic array? linked list? hash table?)
The term "abstract" also comes up in "abstraction," which is some simplification of a complex system into something more managable. For example, network routing is usually broken down into a different number of "layers," each of which are responsible for handling some part of the end-to-end communication. Each layer is tasked with a specific job, and must take in input and produce output in a predetermined fashion. This lets programmers work on one layer treat all the other layers as "black boxes" that magically get the job done, since provided that you give input to the layer in the right form or read the output of some layer in a specific manner, you don't need to worry about the details of how that layer works.
Hope this helps!
Well a good example in OO is an Animal, you'd have an abstract class like so:
abstract class Animal
{
public AnimalType Type { get; set; }
}
Now you can't declare an animal outright, you must have a class that inherits from an animal, like a cat:
class Cat : Animal
{
public Cat()
{
Type = AnimalType.Feline;
}
}
So this wouldn't work:
Animal a = new Animal();
But this would:
Animal a = new Cat();
So in essence, what you're saying, is this is a base class, you can't make one on it's own, you need more information, say a class that inherits from it. Kind of hard to explain, so hope the example helps!
Abstract classes cannot be instantiated and instead are inherited from by other classes, generally concrete ones. They usually contain code that is common to inheriting classes to minimize code duplication.
I think it can mean a couple of things related to programming. But, for me, I think of it related to virtual methods, which may perform different tasks depending on the underlying object type. That would be in contrast to a method that always does the same, fixed set of operations.
In fact there are "abstract classes", where one or more methods are pure virtual, which means they are not implemented by that class. Such a class cannot be instantiated. Instead, you must derive a new class from it that implements the pure virtual methods, and then you can instantiate the second class.
Abstraction is a way of building compound objects from simpler ones. A function for example can be seen a form of black box abstraction ..where the inner workings of the function are hidden from the user.
Data abstraction in general is a methodology that enables programmers to isolate how a compound data object is used from the details of how it is constructed from more primitive data objects.

What is the difference between Type and Class?

What makes a type different from class and vice versa?
(In the general language-agnostic sense)
The following answer is from Gof book (Design Patterns)
An object's class defines how the
object is implemented. The class
defines object's internal state and
the implementation of its
operations.
In contrast, an object's
type only refers to its interface - a
set of requests to which it can
respond.
An object can have many types,
and objects of different classes can
have the same type.
//example in c++
template<typename T>
const T & max(T const &a,T const &b)
{
return a>b?a:b; //> operator of the type is used for comparison
}
max function requires a type with operation > with its own type as one of it interface any class that satisfies the above requirement can be used to generate specific max<particular class/primitive type> function for that class.
Inspired by Wikipedia...
In type theory terms;
A type is an abstract interface.
Types generally represent nouns, such as a person, place or thing, or something nominalized,
A class represents an implementation of the type.
It is a concrete data structure and collection of subroutines
Different concrete classes can produce objects of the same abstract type (depending on type system).
*For example, one might implement the type Stack with two classes: SmallStack (fast for small stacks, but scales poorly) and ScalableStack (scales well but high overhead for small stacks).*
Similarly, a given class may have several different constructors.
The banana example.
A Banana type would represent the properties and functionality of bananas in general.
The ABCBanana and XYZBanana classes would represent ways of producing bananas.
(Different banana suppliers in real life, or different data structures and functions to represent and draw bananas in a video game).
The ABCBanana class could then produce particular bananas which are
instances of the ABCBanana class, they would be objects of type Banana.
It is not rare the programmer provide a single and only implementation for a type. In this case the class name is often identical with the type name. But there is still a type (which could be extracted in an interface if required), and an implementation (which would implement the separate interface) which builds instances (objects) of the class.
I always think of a 'type' as an umbrella term for 'classes' and 'primitives'.
int foo; // Type is int, class is nonexistent.
MyClass foo; // Type is MyClass, class is MyClass
Type is the umbrella term for all the available object templates or concepts. A class is one such object template. So is the structure type, the Integer type, the Interface type etc. These are all types
If you want, you can look at it this way: A type is the parent concept. All the other concepts: Class, Interface, Structure, Integer etc inherit from this concept.i.e They are types
Taken from the GoF citation from below:
An objects's class defines how the
object is implemented .The class
defines the object's internal state and
the implementation of its
operations.
In contrast, an objects's
type only refers to its interface - the
set of requests to which it can
respond.
I want to provide an example using Java:
public interface IType {
}
public class A implements IType {
public A{};
}
public class B implements IType {
public B{};
}
Both classes A and B implement the interface and thus are of the type IType. Additionally in Java, both classes produce their own type (respectively to their class name). Thus the class A is of type A and IType and the class B is of type B and IType satisfying:
An object can have many types,
and objects of different classes can
have the same type.
The difference between subtypes and subclass probably helps to understand that issue as well:
https://www.cs.princeton.edu/courses/archive/fall98/cs441/mainus/node12.html
In general language-agnostic sense - Class is an realization of the Type.
Often when this is the only realization of that type, you can use both terms to reference it in some context.
On the contrary, for example, in C# context - Class is just one of the many more implementations of a Type concept like primitives, structs, pointers etc.
Type contains description of the data (i.e. properties, operations, etc),
Class is a specific type - it is a template to create instances of objects.
Strictly speaking class is a special concept, it can be seen as a package containing subset of metadata describing some aspects of an object.
For example in C# you can find interfaces and classes. Both of them are types, but interface can only define some contract and can not be instantiated unlike classes.
Simply speaking class is a specialized type used to encapsulate properties and behavior of an object.
Wikipedia can give you a more complete answer:
Definition of class
Definition of data type
Type is conceptually a superset of class. In the broader sense, a class is one form of type.
Closely related to classes are interfaces, which can bee seen as a very special kind of class - a purely abstract one. These too are types.
So "type" encompasses classes, interfaces and in most languages primitives too. Also platforms like the dot-net CLR have structure types too.
To illustrate it the fastest way:
A Struct is a Type, but a Struct is not a Class.
As you can see, a Type is an "abstract" term for not only definitions of classes, but also structs and primitive data types like float, int, bool.
I think of a type as being the set of things you can do with a particular value. For instance, if you have an integer value, you can add it to other integers (or perform other arithmetic operations), or pass it to functions which accept an integer argument. If you have an object value, you can call methods on it that are defined by its class.
Because a class defines what you can do with objects of that class, a class defines a type. A class is more than that though, since it also provides a description of how the methods are implemented (something not implied by the type) and how the fields of the object are laid out.
Note also that an object value can only have one class, but it may have multiple types, since every superclass provides a subset of the functionality available in the object's class.
So although objects and types are closely related, they are really not the same thing.
To add another example of distinction: in C++ you have pointer and reference types which can refer to classes, but are not classes in and of themselves.
Bar b; // b is of type "class Bar"
Bar *b2 = &b; // b2 is of type "pointer to Class Bar"
Bar &b3 = b; // b3 is of type "reference to Class Bar"
Bar *b4[7]; // b4 is of type "7-element array of pointers to Class Bar"
Bar ***b5; //b5 is of type "pointer to a pointer to a pointer to Class Bar"
Note that only one class is involved, but a near infinite number of types can be used. In some languages, function are considered "first-class-objects" in which case, the type of a function is a class. In others, the type of a function is merely a pointer. Classes generally have the concepts of being able to hold data, as well as operations on that data.
My thoughts are pretty much in line with aku's answer.
I see classes as a template for building objects, while types are a way to classify those objects, and provide us with an interface to them.
Python also adds metaclasses, that are just a mechanism to build classes, in the same way as classes build objects (and well, classes and metaclasses are both objects).
This response to the same question in lamba the ultimate seems to me like a perfect explanation.
Types in C, like Int Float, char etc define data that can be acted on with specific methods that can operate on them. It's no more complicated than that. Like for int I can add, subtract multiply and maybe divide. Those are my methods (or operations) for int. A Class is simply a definition of a new type. I first define what the data looks like. Maybe its a single bit. Maybe it's two words like a complex with a real and imaginary part. Or maybe its this complex thingy with 309734325 bytes representing the atomic makeup of a weird particle on Jupiter. I don't care. Just like an integer, I get to make up the operations I can do with this new data type. In the case of the integer I had add, subtract, etc. With this new data type I can define whatever operations I think make sense. They might be add subtract etc. but they may add other things. These are whatever methods I decide to add to my class.
The bottom line is that with a type in C, you have a definition of what the data is, ie; a byte, word, float, char etc. But any of these also implies what operations are legal and will produce reliable results.
A class is no different except it is up to you to define the interface and acceptable operations. The class defines these things and when you instantiate it in an Object it defines the behavior of the object just like a type definition defines the behavior of an integer when you operate on it.
Classes just give you the flexibility to define new types and everything about how they operate.
Once this is defined, every time I instantiate an object of class "thingy", it has the data structure I defined and the operations (methods) that I said you can do with it. The class "thingy" is clearly nothing more or less than a new type that C++ lets me define.
Type generally refers to the classification of primitive values - integers, strings, arrays, booleans, null, etc. Usually, you can't create any new types.
Class refers to the named set of properties and methods which an object is associated with when it is created. You can usually define as many new classes as you want, although some languages you have to create a new object and then attach methods to it.
This definition is mostly true, but some languages have attempted to combine types and classes in various ways, with various beneficial results.
Types and classes are related but not identical. My take is that classes are used for implementation inheritance, whereas types are used for runtime substitution.
Here is a link explaining the substitution principle and why subclasses and subtypes are not always the same thing (in Java for example). The wikipedia page on covariance and contravariance has more information on this distinction.
In langugages like Haskell, the concept of Class doesn't exist. It only has Types. (And Type Class. Not to be confused with Class, Type Class is more of an abstracted version of Type).
Monad is a Type Class.
class Monad m where
(>>=) :: m a -> ( a -> m b) -> m b
(>>) :: m a -> m b -> m b
return :: a -> m a
fail :: String -> m a
From a (pure) functional programming perspective, Type is more fundemental than Class as one can trace its root to Type Theory (e.g. from a PTL perspective, lambda calculus with types and without types behave quite differently), while Class is really just a construct to enable OO.
In languages that only support Type and don't support Class, functions are often treated as first-class citizen.
Meanwhile, when a language makes a distinction between Type and Class, functions are more of a second-class citizens that can be attached to Objects, etc. And yup, often you can attach a function onto a Class itself (aka a static function).
Interesting question. I think aku's answer is spot on. Take the java ArrayList class as an example
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
An instance of the ArrayList class is said to be of type of every superclass it extends and every interface it implements. Therefore, an instance of the ArrayList class has a type ArrayList, RandomAccess, Cloneable, and so forth. In other words, values (or instances) belong to one or more types, classes define what these types are.
Different classes may describe the same type.
Type consists of these parts:
Operations = syntax
Description of operations = semantics
Class consists of these parts:
Operations = syntax
Implementation (= various implementations describe same semantics)
Some notes:
Interface (as in Java) is not type, because it does not describe semantics (describes only syntax)
Subclass is not subtype, because subclass may change semantics defined in superclass, subtype cannot change supertype semantics (see Liskov Substitution Principle, e.g. this LSP example).
Obviously, as there are languages with type system that are not OO programming languages, type must be a broader concept than class
Even in languages like Java, int is a (primitive) type, but not a class.
Hence: every class is a type, but not every type is a class.
If we think to this question in C# context, we reach bellow answer.
C# type system is divided into following categories:
Value types:
Simple types: like int, long, float, etc.
Enum types
Struct types
Nullable types
Reference types:
Class types
Interface types
Array types
Delegate types
As you can see there are many types in C# which Class is only one of them.
There is just one important note:
C#’s type system is unified such that a value of any type can be treated as an object. Every type in C# directly or indirectly derives from the object class type, and object is the ultimate base class of all types. Values of reference types are treated as objects simply by viewing the values as type object. Values of value types are treated as objects by performing boxing and unboxing operations.
so as I see, type is an umbrella over many items which class is one of them.
Referece: CSahrp Language Specification doc, page 4
This was a good question for me, which made me think hard. I would dare to say that Class is a compiletime thingy and Type is a runtime thingy. I say this because you write classes not types. The compiler then creates types from classes, and the runtime use types to create instances of objects.
types are programming constructs that helps the compiler to perform type checking and ensure that the variables have the right properties for an operation.
classes are user defined types that an objects or variables referencing them could have. These are also subjected to type checking.