HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <p>The Cartesian coordinate system is not the only way of describing a grid. Another way is the polar coordinate system:</p>
1 <p>The Cartesian coordinate system is not the only way of describing a grid. Another way is the polar coordinate system:</p>
2 <blockquote><p>The polar coordinate system is a two-dimensional coordinate system in which we determine each point on the plane by two numbers - the polar angle and the polar radius. The polar coordinate system helps in cases where the relations between points are easier to represent in the form of radii and angles. We can establish such relations only by applying trigonometric equations in more common Cartesian, rectangular, or coordinate systems. (c) Wikipedia</p>
2 <blockquote><p>The polar coordinate system is a two-dimensional coordinate system in which we determine each point on the plane by two numbers - the polar angle and the polar radius. The polar coordinate system helps in cases where the relations between points are easier to represent in the form of radii and angles. We can establish such relations only by applying trigonometric equations in more common Cartesian, rectangular, or coordinate systems. (c) Wikipedia</p>
3 </blockquote><p>Imagine this situation. We developed a graphic editor like Photoshop and used a library for working with graphic primitives based on the Cartesian coordinate system. At some point, you realize that switching to the polar system will help make everything easier and faster. What price will you have to pay for this change? We have to rewrite almost all the code:</p>
3 </blockquote><p>Imagine this situation. We developed a graphic editor like Photoshop and used a library for working with graphic primitives based on the Cartesian coordinate system. At some point, you realize that switching to the polar system will help make everything easier and faster. What price will you have to pay for this change? We have to rewrite almost all the code:</p>
4 <p>It is because your library does not hide the internal structure. Any code that uses points or segments knows how they work inside. It applies to pieces of code that create new primitives and extract the parts from them. It is simple to change the situation and hide the implementation using functions:</p>
4 <p>It is because your library does not hide the internal structure. Any code that uses points or segments knows how they work inside. It applies to pieces of code that create new primitives and extract the parts from them. It is simple to change the situation and hide the implementation using functions:</p>
5 <p>In the example, we can see three functions:</p>
5 <p>In the example, we can see three functions:</p>
6 <ul><li>The make_point() constructor that creates a new primitive</li>
6 <ul><li>The make_point() constructor that creates a new primitive</li>
7 <li>The get_x() selector</li>
7 <li>The get_x() selector</li>
8 <li>The get_y() selector</li>
8 <li>The get_y() selector</li>
9 </ul><p>Even a small change like this will lead to far-reaching consequences. The main thing is that the application code that uses the library does not work with structure directly:</p>
9 </ul><p>Even a small change like this will lead to far-reaching consequences. The main thing is that the application code that uses the library does not work with structure directly:</p>
10 <p>Looking at the code, you cannot even tell what the point is from the inside or what language constructs it is represented by - you can use debugging printing for this. So, we built a data abstraction. The essence of this abstraction is that we hide the internal implementation. Creating an abstraction using data leads to hiding this data from external code.</p>
10 <p>Looking at the code, you cannot even tell what the point is from the inside or what language constructs it is represented by - you can use debugging printing for this. So, we built a data abstraction. The essence of this abstraction is that we hide the internal implementation. Creating an abstraction using data leads to hiding this data from external code.</p>
11 <p>And there is one way to implement an abstraction when working with a point:</p>
11 <p>And there is one way to implement an abstraction when working with a point:</p>
12 <p>We can change the implementation without having to rewrite the entire code. However, rewriting individual parts may still be necessary. We use the make_point() function, which creates a point based on the Cartesian coordinate system and takes the coordinates x and y as input.</p>
12 <p>We can change the implementation without having to rewrite the entire code. However, rewriting individual parts may still be necessary. We use the make_point() function, which creates a point based on the Cartesian coordinate system and takes the coordinates x and y as input.</p>
13 <p>Also, we can represent it in a polar coordinate system inside. In other words, during construction, we go from one format to another:</p>
13 <p>Also, we can represent it in a polar coordinate system inside. In other words, during construction, we go from one format to another:</p>
14 <p>Once you start working through data abstraction, there is no going back. Always stick to the functions you have created or those provided to you by the library used.</p>
14 <p>Once you start working through data abstraction, there is no going back. Always stick to the functions you have created or those provided to you by the library used.</p>