Layout Options
Which layout option do you want to use?
Wide
Boxed
Color Schemes
Which theme color do you want to use? Select from here.
Reset color
Reset Background
Forums
New posts
Trending
Random
What's new
New posts
Latest activity
Rules
Libraries
New Audios
New Comments
Search Profile Audios
Clubs
Public Events
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Trending
Random
Menu
Log in
Register
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Forums
Boards
/g/ - Technology
What is a class?
Message
<blockquote data-quote="deaf_judger" data-source="post: 71952" data-attributes="member: 390"><p><strong><span style="font-size: 22px">[PLAIN]Functions[/PLAIN]</span></strong></p><p> [PLAIN]In math, we know something like [/PLAIN]$f(x) = x + 1$ [PLAIN]and we'd get Input [/PLAIN]`3' [PLAIN]to Output [/PLAIN]`4' [PLAIN]. Then: What is a function?</p><p> A function is a rule that makes inputs into outputs.</p><p> [/PLAIN]</p><p></p><p><strong><span style="font-size: 18px">[PLAIN]Functions can represent behavior:[/PLAIN]</span></strong></p><p></p><p> [CODE=haskell]</p><p> circleArea :: Double -> Double</p><p> circleArea radius = 3.14 * radius ^ 2</p><p></p><p> [/CODE]</p><p></p><p><strong><span style="font-size: 18px">[PLAIN]Things get messy[/PLAIN]</span></strong></p><p> [PLAIN]Lets say now we want to do</p><p> [/PLAIN]</p><p></p><p> [CODE=haskell]</p><p> circleArea :: Double -> Double</p><p> circleArea radius = 3.14 * radius ^ 2</p><p></p><p> circleCircumference :: Double -> Double</p><p> circleCircumference radius = 2 * 3.14 * radius</p><p></p><p> circleDiameter :: Double -> Double</p><p> circleDiameter radius = 2 * radius</p><p></p><p> radius :: Double</p><p> radius = 1.0</p><p></p><p> circleDiameter radius</p><p> circleCircumference radius</p><p> circleArea radius</p><p> [/CODE]</p><p></p><p></p><p> [PLAIN]Notice how they all operate on the same thing: radius. </p><p> [/PLAIN]</p><p></p><p><strong><span style="font-size: 18px">[PLAIN]Functions cluster around data?[/PLAIN]</span></strong></p><p> [PLAIN]We now have our circles radius, and functions that act on that. The radius is data, and those functions add on it. We have: data + functions that act on it. This is what a class brings together</p><p> [/PLAIN]</p><p></p><p><strong><span style="font-size: 22px">[PLAIN]So what is a class?[/PLAIN]</span></strong></p><p> [PLAIN]A class is a bundle of data and functions that operate on the data. So instead of circleArea(radius) we write circle.area(). We attach the function to the data.But, radii of circles does not really demonstrate my point properly. I will switch.</p><p> [/PLAIN]</p><p></p><p><strong><span style="font-size: 18px">[PLAIN]Can we express a class in math?[/PLAIN]</span></strong></p><p> [PLAIN]A class can be a pair?:</p><p> [/PLAIN]$C = (S,M)$[PLAIN]</p><p> Where: [/PLAIN]$S$ [PLAIN]is the data and [/PLAIN]$M$ [PLAIN]is a set of methods that transform the state. Each method is a function. For example we have a bank account:</p><p> [/PLAIN]</p><p> \begin{equation}</p><p> S = \{ bank balance, account owner \}</p><p> F = \{ deposit,withdraw \}</p><p> \end{equation}</p><p></p><p> [PLAIN]and each function looks something like</p><p> [/PLAIN]</p><p> \begin{equation}</p><p> deposit: S \times amount \to S</p><p> \end{equation}</p><p> [PLAIN]So, the class transfors the state. So a class is a state space + state transition functions</p><p> [/PLAIN]</p><p></p><p><strong><span style="font-size: 18px">[PLAIN]What do classes do?[/PLAIN]</span></strong></p><p> [PLAIN]Classes let us make many states that have the same rules. Say we have three bank accounts with their own states. They will share the same functions. [/PLAIN][therefore] [PLAIN]classes separate rules and instances.</p><p> [/PLAIN]</p><p></p><p><strong><span style="font-size: 18px">[PLAIN]So then a class defines state machine?[/PLAIN]</span></strong></p><p> [PLAIN]Yes. methods are transitions. Each method moves the bank account from one state to another, and an object is an instance running that.</p><p> [/PLAIN]</p></blockquote><p></p>
[QUOTE="deaf_judger, post: 71952, member: 390"] [B][SIZE=6][PLAIN]Functions[/PLAIN][/SIZE][/B] [PLAIN]In math, we know something like [/PLAIN]$f(x) = x + 1$ [PLAIN]and we'd get Input [/PLAIN]`3' [PLAIN]to Output [/PLAIN]`4' [PLAIN]. Then: What is a function? A function is a rule that makes inputs into outputs. [/PLAIN] [B][SIZE=5][PLAIN]Functions can represent behavior:[/PLAIN][/SIZE][/B] [CODE=haskell] circleArea :: Double -> Double circleArea radius = 3.14 * radius ^ 2 [/CODE] [B][SIZE=5][PLAIN]Things get messy[/PLAIN][/SIZE][/B] [PLAIN]Lets say now we want to do [/PLAIN] [CODE=haskell] circleArea :: Double -> Double circleArea radius = 3.14 * radius ^ 2 circleCircumference :: Double -> Double circleCircumference radius = 2 * 3.14 * radius circleDiameter :: Double -> Double circleDiameter radius = 2 * radius radius :: Double radius = 1.0 circleDiameter radius circleCircumference radius circleArea radius [/CODE] [PLAIN]Notice how they all operate on the same thing: radius. [/PLAIN] [B][SIZE=5][PLAIN]Functions cluster around data?[/PLAIN][/SIZE][/B] [PLAIN]We now have our circles radius, and functions that act on that. The radius is data, and those functions add on it. We have: data + functions that act on it. This is what a class brings together [/PLAIN] [B][SIZE=6][PLAIN]So what is a class?[/PLAIN][/SIZE][/B] [PLAIN]A class is a bundle of data and functions that operate on the data. So instead of circleArea(radius) we write circle.area(). We attach the function to the data.But, radii of circles does not really demonstrate my point properly. I will switch. [/PLAIN] [B][SIZE=5][PLAIN]Can we express a class in math?[/PLAIN][/SIZE][/B] [PLAIN]A class can be a pair?: [/PLAIN]$C = (S,M)$[PLAIN] Where: [/PLAIN]$S$ [PLAIN]is the data and [/PLAIN]$M$ [PLAIN]is a set of methods that transform the state. Each method is a function. For example we have a bank account: [/PLAIN] \begin{equation} S = \{ bank balance, account owner \} F = \{ deposit,withdraw \} \end{equation} [PLAIN]and each function looks something like [/PLAIN] \begin{equation} deposit: S \times amount \to S \end{equation} [PLAIN]So, the class transfors the state. So a class is a state space + state transition functions [/PLAIN] [B][SIZE=5][PLAIN]What do classes do?[/PLAIN][/SIZE][/B] [PLAIN]Classes let us make many states that have the same rules. Say we have three bank accounts with their own states. They will share the same functions. [/PLAIN][therefore] [PLAIN]classes separate rules and instances. [/PLAIN] [B][SIZE=5][PLAIN]So then a class defines state machine?[/PLAIN][/SIZE][/B] [PLAIN]Yes. methods are transitions. Each method moves the bank account from one state to another, and an object is an instance running that. [/PLAIN] [/QUOTE]
Insert quotes…
Name
Verification
Post reply
Forums
Boards
/g/ - Technology
What is a class?
Top