[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


Hi guys, I have been learning how to program in C# for about two weeks now. How do I learn the basics of object-oriented programming? How did you guys learn object-oriented programming in C#?

WHat I can do so far:
>variabels
>strings
>loops
>methods
>classes (basic)
>>
I don't
>>
I'd like to help but I'm in shrink the game mode right now
>>
File: glasses two peace signs.jpg (813 KB, 2393x3429)
813 KB
813 KB JPG
most of what you have seen so far is basically the same across all imperative languages. methods, classes and objects are the basic OOP concepts
put simply an object is like a particular gingebread man and the class is the cookie cutter shape for generating gingerbread men
you dont really do operations on classes (like eating the shape of a gingebread man) instead you do operations on objects or instances (like the gingerbread men)
classes also define what kinds of operations can be done on objects of its kind
this would be akin to a gingerbread cookie cutter having an abstract set of instructions for eating, such that you can eat or decorate or snap in half particular gingebread man by calling gingerbread_man.eat()
particular gingebread men are different from eachother in things like frosting. this is also how objects differ from eachother even though they instantiate classes
this is basically Platonism btw which is kind of funny
>>
>>108445815
>particular gingebread men are different from eachother in things like frosting. this is also how objects differ from eachother even though they instantiate classes
I'd phrase this part a little differently, for the sake of clarity:
You can make two gingerbread men completely identical, in shape, size and frosting, but they're still two separate objects - if you take a bite out of one, the other is unaffected
>>108445731
There are however two times this doesn't apply:
1) if a class is created with the keyword static, you can't create multiple instances of it, there is just one global instance. A good example would be the class Math that you use to use methods such as Round() or Sqrt() - Math has properties and methods, but you can't create an object of the type Math
2) if a property is in a non-static class is declared as static, that property becomes a "shared resource" of sorts:
Imagine a group of people sitting around a table, eating soup from one big pot - all of these people are their own distinct individuals (separate instances of a class), but they are all sharing one big (static) pot of soup - if you want to change what one of them is eating, it will automatically change for all of them
>>
>>108445731
Just build something
>>
I hate these analogies for classes and instances so much. It only makes sense in your head because you already understand how classes and instances work. To someone who doesn't, it's hard to connect it back to programming.

I'd prefer to just describe it as it is. An object (or instance) is just a container of various data fields and functions that have access to read/write to those fields and do whatever other logic you want. The class defines which fields and functions the object/instance you create from the class has. The class is defined using something like
public class ThingWithData {
and you create an object like
var thing = new ThingWithData();
The purpose is to compartmentalize data and functions together for better organization for 1, but more importantly so that you can reason about your program easily - if you change the value of a variable that belongs to an object, you know that only the object has access to that variable (assuming it's private), so you have a limited number of things that can be affected/break by that code change you just made.

It's conceptually not super different from writing a program that is just functions that call each other, but with functions you can kind of only call function B from function A and save the return value of function B in a local variable in function A. If you substitute this with an object of class A instantiates an object of class B, you can just store instance B in a variable that belongs to instance A and retain all the stuff (data and functrions) inside of B that you can access from inside A at a later time. It's like instead of just being able to call 1 function you get this object that may contain many functions and data that you can all access separately and it's just provided to you in this convenient centralized bundle



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.