473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fundamental OOP inheritance question

RSH
Hi,

I have been construction a sample application to further my growth in
applying OOP concepts in .Net.

My code is structured like this:

Person |-- Employee
|--- Customer

CatalogItems

Order

OrderLineItems

So my instantiation looks like this:
Dim i1 As CatalogItems = New CatalogItems(100, "Bottle", 19.95)

Dim i2 As CatalogItems = New CatalogItems(200, "Can", 10.95)

Dim i3 As CatalogItems = New CatalogItems(300, "Box", 22.95)

Dim c1 As Customer = New Customer(11111111, "Jim Williams", "123 Main St.",
"Atlanta", "GA", "30188")

Dim c2 As Customer = New Customer(12212221, "Fred Smith", "445 Fieldstone
Pkwy", "Royal Oak", "MI", "48098")

Dim no1 As Order = New Order(1000, c1, Now())

no1.AddLineItem(i1, 23)

no1.AddLineItem(i3, 12)

no1.PrintInvoice()

My question revolves around inheritance. When i create a New Order Object,
I am passing it a customer object. The dynamic nature of this is evident
when I create a new order the customer object becomes part of the of the
order. If I change the property FIRST_NAME from Jim to James for example it
progates down to the order as well. Is there anyway to freeze certain
properties in the customer object so that any changes to the FIRST_NAME
Property only affect the main class...not the sub clasess?


Nov 3 '06 #1
4 1025
I don't understand what you mean by 'propagates down to the order'.

There is only one Customer object instance. It is the only thing that has
the FIRST_NAME property. There may be serveral references all pointing to
this Customer instance - but they are all pointing to the same location in
memory. It doesn't matter which reference you are using to get to this
Customer, because they are all pointing to the same thing.

So there is no propogation. Anything pointing to this one Customer will see
exactly what everything else pointing to it sees.

If you want to change the Customer variable c1, but not have the Customer of
no1 changed, then you can't pass 'c1' to the constructor of Order. You have
to create a brand new Customer object which happens to be an exact copy of
'c1', and pass that. That way, you will have 2 Customer objects in memory,
that are completely independent.

"RSH" <wa*************@yahoo.comwrote in message
news:ej**************@TK2MSFTNGP02.phx.gbl...
Hi,

I have been construction a sample application to further my growth in
applying OOP concepts in .Net.

My code is structured like this:

Person |-- Employee
|--- Customer

CatalogItems

Order

OrderLineItems

So my instantiation looks like this:
Dim i1 As CatalogItems = New CatalogItems(100, "Bottle", 19.95)

Dim i2 As CatalogItems = New CatalogItems(200, "Can", 10.95)

Dim i3 As CatalogItems = New CatalogItems(300, "Box", 22.95)

Dim c1 As Customer = New Customer(11111111, "Jim Williams", "123 Main
St.", "Atlanta", "GA", "30188")

Dim c2 As Customer = New Customer(12212221, "Fred Smith", "445 Fieldstone
Pkwy", "Royal Oak", "MI", "48098")

Dim no1 As Order = New Order(1000, c1, Now())

no1.AddLineItem(i1, 23)

no1.AddLineItem(i3, 12)

no1.PrintInvoice()

My question revolves around inheritance. When i create a New Order
Object, I am passing it a customer object. The dynamic nature of this is
evident when I create a new order the customer object becomes part of the
of the order. If I change the property FIRST_NAME from Jim to James for
example it progates down to the order as well. Is there anyway to freeze
certain properties in the customer object so that any changes to the
FIRST_NAME Property only affect the main class...not the sub clasess?




Nov 3 '06 #2
When you assign the customer to the Customer property in your order record,
you are telling it to point to the same instance, the same portion of memory,
as the original customer instance. The only way to break them is to make
a member-wise copy of the customer entry. That is, create a new customer
instance and copy properties from the original to the copy. Of course, this
is risky as it could cause data to get out of sync.

Sometimes it is useful to retain the original shipping address on an order,
even if the customer moves at a later time. In that case, you need to make
separate copies of the address and store them with the order, and not with
the customer record.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
Hi,

I have been construction a sample application to further my growth in
applying OOP concepts in .Net.

My code is structured like this:

Person |-- Employee
|--- Customer
CatalogItems

Order

OrderLineItems

So my instantiation looks like this:
Dim i1 As CatalogItems = New CatalogItems(100, "Bottle", 19.95)
Dim i2 As CatalogItems = New CatalogItems(200, "Can", 10.95)

Dim i3 As CatalogItems = New CatalogItems(300, "Box", 22.95)

Dim c1 As Customer = New Customer(11111111, "Jim Williams", "123 Main
St.", "Atlanta", "GA", "30188")

Dim c2 As Customer = New Customer(12212221, "Fred Smith", "445
Fieldstone Pkwy", "Royal Oak", "MI", "48098")

Dim no1 As Order = New Order(1000, c1, Now())

no1.AddLineItem(i1, 23)

no1.AddLineItem(i3, 12)

no1.PrintInvoice()

My question revolves around inheritance. When i create a New Order
Object, I am passing it a customer object. The dynamic nature of this
is evident when I create a new order the customer object becomes part
of the of the order. If I change the property FIRST_NAME from Jim to
James for example it progates down to the order as well. Is there
anyway to freeze certain properties in the customer object so that any
changes to the FIRST_NAME Property only affect the main class...not
the sub clasess?

Nov 3 '06 #3
RSH,

The basic thing from using Objects is that an Object can be referenced from
many places, but that created object stays the same.

If I phone you and you are on another place as usuasly however have set in
your standard telephone that you are in another place than I can reach you.
That is because that you have added a reference. You stay however the same
person on whatever place you are.

Dim RSH as new Person
Dim RSHOtherplace as Person = RSH

RSH and RSHOtherplace are referencing to the same object, which is exactly
the wanted behaviour in object oriented programming.

If you don't that but are talking about another person than you do
Dim RSH as new Person
Dim Another as new Person

I hope that I answer your question in other words.

Cor
"RSH" <wa*************@yahoo.comschreef in bericht
news:ej**************@TK2MSFTNGP02.phx.gbl...
Hi,

I have been construction a sample application to further my growth in
applying OOP concepts in .Net.

My code is structured like this:

Person |-- Employee
|--- Customer

CatalogItems

Order

OrderLineItems

So my instantiation looks like this:
Dim i1 As CatalogItems = New CatalogItems(100, "Bottle", 19.95)

Dim i2 As CatalogItems = New CatalogItems(200, "Can", 10.95)

Dim i3 As CatalogItems = New CatalogItems(300, "Box", 22.95)

Dim c1 As Customer = New Customer(11111111, "Jim Williams", "123 Main
St.", "Atlanta", "GA", "30188")

Dim c2 As Customer = New Customer(12212221, "Fred Smith", "445 Fieldstone
Pkwy", "Royal Oak", "MI", "48098")

Dim no1 As Order = New Order(1000, c1, Now())

no1.AddLineItem(i1, 23)

no1.AddLineItem(i3, 12)

no1.PrintInvoice()

My question revolves around inheritance. When i create a New Order
Object, I am passing it a customer object. The dynamic nature of this is
evident when I create a new order the customer object becomes part of the
of the order. If I change the property FIRST_NAME from Jim to James for
example it progates down to the order as well. Is there anyway to freeze
certain properties in the customer object so that any changes to the
FIRST_NAME Property only affect the main class...not the sub clasess?




Nov 4 '06 #4
RSH wrote:
My question revolves around inheritance.
If I change the property FIRST_NAME from Jim to James for example it
progates down to the order as well.
No it doesn't. The Order object has a /reference/ to a Customer object.
If you have /another/ reference to the same Customer object and change
a value on that object, then the change is apparent in both places,
because they are both using the /same/ object.

Class Simple
Public Sub New( ByVal sName As String )
...
Property Name() As String
...
End Class

Dim p1 As New Simple( "Fred" )
Dim p2 As Simple = p1

?p1.Name
"Fred"

p2.Name = "Barney"

? P1.Name
"Barney"
Is there anyway to freeze certain properties in the customer object so
that any changes to the FIRST_NAME Property only affect the main class...
not the sub classes?
Not usually, no.

HTH,
Phill W.
Nov 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Casper Bang | last post by:
My question is fundamental I beleive but it has been teasing me for a while: I have two classes in my app. The first class is instantiated as a member of my second class. Within this first class,...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
1
by: liming | last post by:
I have installed postgresql 8.3.1,import data from a dB to another one.I work in pgadmin 3 . When I choose a table ,select the characteristic?it shows the problem below? Error:relation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.