|
You only use inheritance if B "is a" A. Not if B "has a" A.
Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects.
Source[^]
led mike
|
|
|
|
|
Then what about private inheritance in C++? This does exactly what the OP is after.
Steve
|
|
|
|
|
I am not sure what you are getting at.
led mike
|
|
|
|
|
What I'm saying is that in C++ private inheritance doesn’t really model an is-a relationship (not to the users of the class; internally to the class it does) but is inheritance nevertheless. e.g.
class CMyClass : private CMyBase
{
};
Steve
|
|
|
|
|
Sorry I have no idea what your point is. The capabilities of a specific language don't alter the principles of Object Oriented Analysis and Design.
led mike
|
|
|
|
|
hi ,
I'm a pretty simple self taught developer. I did do some reading on business objects , 3-tiered apps etc and i just got myself a book on OOAD.
But i'm still not very clear about decoupling the data layer and the business layer.
In my DB i have 2 tables -Rooms and Persons:
Rooms:
RoomID
Cost
PersonID
Persons:
PersonID
Name
LastName
Age...
...
So , my business objects[Room , Person] are pretty much a class with properties corresponding the columns in the table.
I need to have a cache of all Persons and all Rooms , so dont keep accessing the DB all the time.
Should my data layer do this: (Should the DataLayer know the existence of the business class??
List<person> GetPersons()
{
//open a connection...(sql servr 05)
//get data
//iterate through all the persons ..
lstTemp.Add(new Person**(strName , strLastName , iAge...));
//end iterate
return lstTemp;
}
Also , i did say the classes are just like the columns. Persons.PersonID & Rooms.PersonID have a relatioship in the DB
the Person class has:
+int PersonID
+string name
...
And Room :
+int RoomID
+int cost
...
(They hold IDs just like the DB)
After my app loads , i have a seperate List<> of Persons and Rooms , and if i need to know what Person is in a particular room , like DB access , i have to Traverse the Persons list in memory to find the right Room.PersonID
This is not correct right? Is there some article book or anything that would educate me on how to do this right!???
Thanks so much
Gideon
|
|
|
|
|
|
hi ,
thanks for replying. Acutally , i've been told to use an O/RM solution before.(checked nHib) But i already wrote a datalayer(and spent quite some time on it). So i'm a little stubborn about that.
Acutally i've described a simplified version of my framework. I'm just a little confused about how i should store a cache of my objects and access them real quick without having my custom controls need pointers via a property to a List<> of Persons , Rooms , Reservations......etc
I read some more on DALs , i've seen examples with one object holding referenced to many child objs like a one-to-many relation. But some of my relations are a little more complex.
I have
class Customer: //just a way to group many Persons, could call it Group.
+Name
+List<> Persons
But Reservation has
+StartDate
+EndDate
+PersonID //if i had reference to a Person obj here , how would i get the parent customer? Should Each person have a .Parent property!??
Thanks so much
Gideon
|
|
|
|
|
Well, your case might not warrant a seperate layer.
For one though, if you want your app to scale well, then holding all of the data in memory might not be reasonable.
Say this is a website you're starting for a new business. The worst thing that can happen is that it succeeds, and you have 20,000 records to hold in memory.
The main purpose of seperating out the data layer is if you're building an app that needs to target multiple data sources. If you will only ever need just the one source, then you might not need to worry about it.
I would recommend though, that you put the data access code in a seperate file. So that your business objects can stay slim for serialization purposes.
Sounds like your situation doesn't warrant worrying too much about it. But as it grows and if you plan to target more than one database (say its a reservation system you'll sell to mutliple clients) then you might benefit from it.
This statement was never false.
|
|
|
|
|
Hi,
I have a query regarding what would be a 'best practice' for SEH in an asp.net web app. At present I have Object as my return type from class functions. Within these functions use a try...catch block and return an error object if there's an error or the correct type, say datatable if the process completes as expected. The calling sub then evaluates the returned type and acts accordingly. While this works ok for me, it is a bit long winded and I can't help feeling I am missing the point somewhere. What do you guys do? Thanks if anyone has any tips.
Shaun
If I had all the money I'd spent on drink, I'd spend it on drink - Sir Henry at Rawlinson's End
|
|
|
|
|
Exceptions are special in that when one is thrown, the .NET runtime will go up the function call-stack until it finds a catch block that can handle the exception. What this means is that you can put a try-catch at the "root" function (the one that calls all the other functions) and any exceptions thrown by any lower functions will be caught in the root function's catch block.
Here's an example:
Sub Main()
Try
DoStuff1()
Catch ex As Exception
' Handle exception
End Try
End Sub
Private Sub DoStuff1()
DoStuff2()
End Sub
Private Sub DoStuff2()
DoStuff3()
End Sub
Private Sub DoStuff3()
' Generate an exception
End Sub
If DoStuff3 generates an exception, .NET will jump to the catch block in Main. This way you can assume that all the values returned from your functions will be correct since if there was an error in the function, .NET would jump to the outer catch block, skipping any code that used the return value.
|
|
|
|
|
I see...
Thanks
Shaun
If I had all the money I'd spent on drink, I'd spend it on drink.
|
|
|
|
|
Is there any programs using which I can design interface of my program before I actually start coding? Something lightweight program that we let me to design or scratch the program. Do you use any program like this? Which? Thanks
|
|
|
|
|
|
Yes I thought about that but computer would be easier,faster, more beautiful and realistic
|
|
|
|
|
Giorgi Dalakishvili wrote: computer would be easier,faster
How would a computer be faster than you with a pen and paper? Seriously, blocking out the general interface using pen and paper is much quicker - you just need to work out what goes where and if you don't like the positioning, you can easily start again.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I already have some general view of the application and I would like to make a model in computer now. If you now some software for that please write. I haven't posted this in order to argue which is better
|
|
|
|
|
Visio then.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Something more lightweight?
|
|
|
|
|
Visual Studio. Seriously, it's fairly trivial to knock up the framework of your application in VS.NET - and then you'll have something to build on later.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
absolutely. VS is also quicker to make a a mockup than visio, and visio's fake app controls don't look exactly like the real thing either.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
The Grand Negus wrote: Pete O`Hanlon wrote:
Visual Studio. Seriously
It's been a long time since I heard those three words together in a thread where the guy asked for something "lightweight"!
Oh - to be able to award you 10 points for that.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Well, the three tools I use are:
* Pen and paper (or whiteboard if I need to share in realtime)
* Visio (for documentation)
* Visual Studio (because the class diagram gives me what I need and it is easy to create stub code to start off with)
|
|
|
|
|
I found this: http://www.carettasoftware.com/gds/index.html
not professional but can be helpful
|
|
|
|
|