flâneur — a map of the web's best reading

4. Encapsulation - CS2030S Programming Methodology II

nus-cs2030s.github.io · 1,249 words · saved by 1 readers

Just like functions allow programmers to group instructions, give it a name, and refer to it later, a composite data type allows programmers to group primitive types together, give it a name (a new type), and refer to it later. This is another powerful abstraction in programming languages that help us to think at a higher conceptual level without worrying about the details. Commonly used examples are mathematical objects such as complex numbers, 2D data points, multi-dimensional vectors, circles, etc, or everyday objects such as a person, a product, etc. Defining composite data type allows programmers to abstract away (and be separated from the concern of) how a complex data type is represented. For instance, a circle on a 2D plane can be represented by the center (x, y) and its radius r, or it can be represented by the top left corner (x,y) and the width w of the bounding square. In C, we build a composite data type with struct. For example, Once we have the struct defined, we are not

Unit 4: Encapsulation After reading this unit, students should understand composite data type as a even-higher level abstraction over variables understand encapsulation as an object-oriented (OO) principle understand the meaning of class, object, fields, methods, in the context of OO programming be able to define a class and instantiate one as an object in Java appreciate OO as a natural way to model the real world in programs understand reference types in Java and its difference from the primitive types Abstraction: Composite Data Type Just like functions allow programmers to group instructio

Explore this link on the map →

saved by

related reading