I am not sure anymore what overloading is.
Overloading is providing multiple methods with the same name but a different signature. THe methods must differ by argument, not return type.
Walk()
Walk(int distance)
Walk(double speed)
Walk(int distance)
Walk(int distance, double speed)
Overloaded Walk()
Walk() could be in the parent class, and the other derivatives in the subclass. There is no need for the subclass to override Walk() jsut to be able to overload it
Override and Overload are different things. Override is used to replace parent functionailty, Overload is used to add variety to it
A third keyword, Shadows is like Override but it does not replace parent functionality, it allows both to exist side by side. WHich version is called, depends on the "Box" that the child is in:
Dim ani as Animal = New Dog
Dim dog as Dog = New Dog
ani.WalkShadows() 'parent Animal implementation is called
dog.WalkShadows() 'child Dog implementation is called
Encapsulation:
Is this where you create your get and set?
Encapsulation is putting everything in its rightful place. When you tidy your house, you put books on the bookshelf, plates in the cupboard and toilet roll in the bathroom.
Each class should take care of its own data, not fiddle with anyone elses data, and expose only necessary details to the outisde world. When your DVD player plays a DVD you press the PLAY button. You dont short wire 27 of jumper 3 to ground then connect pin 4 of IC 35 to +5V. You use the dvd players interface, you dont care how it works, you dont reach into the dvd player and fiddle (you dont rewind the disc by putting your finger on it and spinning it backwards)
Get and Set allow for code verification of values passed in and taken out. Getting the DVD length when there is no dvd inserted; do we return null? 0? throw an exception? You decide in the Get.
I prefer to give the example of shapes when explaining this.
Shape has number of sides the programmer must set, a colour and a size the user can set
Triangle is a child of shape, is 3 sides
Square is a child of shape, is 4 sides
Suppose shape has a MustInherit (must implement in the child) method called GetBitmap() that returns a bitmap image representing this shape, colour, size etc
The user is running a paint program, and the list of things drawn is an array:
Dim shapes(0 to 9) As New Shape
shapes(0) = new Triangle(red, 1) 'size 1
shapes(1) = new Square(blue, 4) 'size 4
Now to render them all on screen:
For Each s As Shape in shapes
drawingCanvas.PaintBitmap(s.GetBitmap() )
Next s
Here's the polymorph:
element 0 is a small red triangle, a small red triangle is drawn WITHOUT the parent calls needing to now exactly how to deal with a Triangle
element 1 is a large blue square, and again, the parent class knows nothing of Squares, it only needs to know shapes
It is the shape itself, that knows how to draw a bitmap of itself
I'm still not sure what Abstraction is, can anybody explain me?
That concept we talked about above. Shape is abstract. You cannot make a Shape, but you can make a Triangle. Shape is a concept, Triangle is the realisation. Absrtaction also necessarily includes "Information hiding".
Look at a roadmap. Where are the birds? The trees? The houses? The gradients and contours? The footpaths?
Look at an ordnance survey map. Where are the road numbers/names? Where are the junction numbers? Why are some A roads pink and others green? Where are the photorealistic mountains?
Look at a geographical relief map. Where are the buildings? Where are the theatres?
These are all maps, but they dont represent the country in infinite detail 1:1 scale, they dont all show the same info. Road users dont care about footpaths; the footpaths are still there but the map doesnt show them because it is unneccesary info. Information hiding. Abstracting something involves hiding the bits we dont need, so we can deal with it at some level. Maps that contained everything would be very confusing. Just open Google Earth and switch on all the overlays, youll see what I mean..
I think it is very difficult to define your objects in OOP.
THey usually align with the real world. Dont go mental though. If youre modelling a train station, dont model the cigarette butts on the floor, unless they really have some purpose. (Abstraction)
If you have a form which can create, delete, insert and change records, what will the objects be?
Form is one object, and the record holding the data is another. A third component adopts the role of a pump, moving the data around
Will they be create, delete, insert and change?
No. Create, delete, insert and change are VERBS; doing words, actions. By simple English grammar, they are not NOUNS; objects, things.
Create is an action of the pump. It creates a record object. Delete is an action of the pump; it takes in a record to delete and finds and deletes it from the back end store. Insert takes in an object and writes in in the backend store. Change locates the backend record and syncs it with the passed object
Also 1 object for the form itself?
Yes
Reading some fragments on internet about OOP doesn't make it easier to understand for me
Thats howcome universities can make a 4 year course of it