how implementation OOP...???

angstetra

Member
Joined
Feb 4, 2007
Messages
10
Programming Experience
Beginner
Hi... i have project which the requirement to implement the OOP into the project. i choose library management system... i do not know.. where i must implement OOP. especially in Inheritance and Polymorphism... anyone can help me to give me idea...??? thank you.. so much....
 
OOP - object oriented programming..

For example in a library management system, u defined the objects.

Like what u may think, let me give u some examples

Likes Books, administrators, members.. these are generalizations, so from here how do we inheritance??

there are common attributes towards objects.. like for example, the book object can be a reference book, a story book, a comic etc. etc..

So u implement Book. the parent class which contains what a book should usually have like for example title, published date..

and then inheritance come in,

Reference book is a type of book and so the child class would be Reference Book and so on.. whatever type of book u can think of..

Thus, Reference book class, would contain a special set of variables that ONLY this type of object have.. and the other variables and methods inherited from the parent class Book which are common across all the books in the library. Same as for members, you can have premium members ordinary members etc etc..

Polymoriphism would simply means method overloading and overridding.. using abstract class and stuff like that

Here is a nice pretty guide for you to pick up oop for vb.net cheers
http://www.codeproject.com/vb/net/OOPS_In_VBNET.asp
 
Well todat I've started to read about OOP but untill now it a very abstract theory and sometimes I am not sure how practical examples should look like in VB .NET but I guess that also comes due to the fact that I do not master VB .NET itself.
Anyway it is a very interesting theory and eventually I want to spent more time on it.
 
Yeah me too.

OK I'll give it a try, do I understand this right?

Encapsulation:
2 objects are sending messages to each other. My dataset says to my textbox: Here, take this value:
VB.NET:
Textbox1.Text = ds.Tables("Test").Rows(inc).Item(0)

Inheritance:
I have a class of which I create a subclass:
VB.NET:
 Dim con As New SqlConnection = "bla bla"
This "con" can have it's own properties and methods, but inherits properties and methods of the class SqlConnection.

Polymorfism:
I don't have a practical example but is following right?
If I have 2 classes, a cat and an alligator. Both classes have the method "eat", but both handle this "eat" in another way. "eat" for the alligator is done different then for the cat.

I'm still not understanding anything of this overloading, overriding, abstract classes and so on, but if I understand this above right I can look further.
 
Inheritance:
You have a class called animals and defined some properties (e.g. colour) and methods (e.g. walk) for it.
You also want to describe a dog but you want to add some extra methods and properties. Here's where inheritance comes in. You can inherit all the properties of the animal class but add your own method "barking" in it.
You do this with the following code:

VB.NET:
class dog
  inherits animals
end class

You can even override a method from the parent class (animals). Let's assume that a dog can walk in another way then a typical animal. You could then override the method "walk" of the class animals.
This is called overriding. I am not sure anymore what overloading is.

Encapsulation:
Encapsulation is very simple. Let's say you have a waitress and a cook. The waitress has an order from the client and passes it to the cook. She doesn't care how the cook makes the dinner, he just has to make it. The cook doesn't care how the waitress serves the food.
In this case you have 2 classes, cook and waitress. The waitress tells the cook what the client wants, so she says cook(omelet). The cook internally will know what to do in order to make this omelet.
In programming this gives the advantage that you don't have to know what's in the other class to do something. You just tell the class to do something.
Good encapsulation takes care for it that it's own variables cannot be changed from outside, they should be kept Private and not Public.
Is this where you create your get and set?

Polymorphism:
Let's go back to our classes animals and dog. We create a new class called alligator.
We want the alligator to walk so we give him the method walk.
We also want the dog to walk so we also give him the method walk.
Now a dog walks different then a crocodile, so internally there should be another handling of the code.
Polymorphism takes care for it that you have the same methodname so everybody immediately knows what you mean with it. You don't have to create methods like walk_dog and walk_alligator.


I'm still not sure what Abstraction is, can anybody explain me?

I think it is very difficult to define your objects in OOP. If you have a form which can create, delete, insert and change records, what will the objects be? Will they be create, delete, insert and change? Also 1 object for the form itself?

I hope I'm right what I've stated above so I can also help other people. Reading some fragments on internet about OOP doesn't make it easier to understand for me :)
 
Well todat I've started to read about OOP but untill now it a very abstract theory and sometimes I am not sure how practical examples should look like in VB .NET but I guess that also comes due to the fact that I do not master VB .NET itself.

That's not quite the right way to think about it.. OOP is a way of thinking, VB.NET is a way of writing. Learn how to think first, then you can express yourself in any language. If you only learn how to write, you wont ever learn properly how to think because your writing limits your thinking to only what you can write.

I see it a lot in the form of language resistance; people really think that VB.NET, C#, java etc are very different; they really arent. When you dispose of all the keyword syntax, you realise that the semantics are identical
 
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.

Polymorphism:
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:

VB.NET:
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
 
Last edited:
Wow thnx for the explanation!! It is much clearer now.
I've never programmed before and when I started to write VB.NET 3 weeks ago, ofcourse I started to write in procedural programming.
I want to learn OOP because it has so many advantages against procedural programming, so I think I'll leave my current programs as they are and start to get into OOP.

Is OOP actually intensively used in businesses? Our software here is definitely not OO and the programmers I know use about 10% OOP when they program.

I've also read that UML is a good way to start using OOP. When you have your UML drawing (classdiagram) you actually have the blueprint for your program.

I only have one problem, it's too interesting *grin*
 
Yep.. With the exception of some VB6, where I used class modules extensively, I've been writing full OO programs for more than 10 years now..

All books that I find on the internet about OO or UML are all talking about Java and not about VB.NET :(
 
Back
Top