Originally Posted by
Kytres
3. Can anyone explain is super plain words what a object is with its atributes and methods? I already know what it is but it help me cement stuff when its explained plainly by people who used them for a longer time.
Typically, an object is a black box that contains something you want. The box has no obvious ways to get inside it, but it has 0 or more buttons on it that you can press to get information about the contents, or the actual contents, or to put more things in the box.
For example, consider a CandyBox class you see at the Dollar Class Mart. It is wrapped in plastic, but you can see from the picture on the wrapping that it has various buttons for finding out the type and number of various sweet candy it has inside. There are buttons for loading more candy, for dumping out all candy, for getting a specific candy, for displaying how many candies are inside, and so on.
You buy the CandyBox class and take it home. You unwrap it and plug it into an electrical outlet (that is, you "instantiate" a candyBox object).
(Because the manufacturers are not stupid, they have made the CandyBox a "singleton"; don't worry about this for now, but assume you can have only one candyBox object.)
Now you see that you have a working candyBox (an object) that has various buttons and sliders and switches (methods). By pressing buttons, moving sliders, and hitting switches (invoking methods), sometimes you get candy (data), or information about the candyBox or the specific contents (properties). You can even pour your own candy into the candyBox and press a button to load it up with your favourite candy!
Oops, but not _any_ candy! Because the candy company is a little evil, you have to use candy that is a type of the Candy made by World Domination Candy Corp (inherits or implements from com.domination.Candy). This requires buying from the same or different vendor some pre-created candy bags (objects) that you can load into the candyBox before pressing the "loadCandy" switch [invoke the loadCandy() method with a Candy parameter].
Or you can buy the CandyFactory product from another store made by another company that allows you to make your own myTastyCandy (an object derived from your own MyTastyCandy class that conforms to the com.domination.Candy interface, probably) and use that in the same way.
Oh, I should mention that World Domination Candy Corp workers know how to open up the box even though it is impossible for you. Inside are _more_ buttons and sliders and switches that they know how to use. These might do things like limit the number of candies, hide or disable some of the "public" buttons, or generally maintain specifics and details about the operation of a candyBox you, as the candyBox user (client) don't care about.
Then the analogy breaks down quickly and I find I'm terribly hungry.