|
Hello experts,
I'm working on a system which would be able to dinamically load all kinds of multiplayer games.
In order for the system to know how to handle any game, I set up some ground rules using an abstract class named GameEngine .
Among other stuff, it contains an abstract ProcessMessage() method.
At first I thought of loading DLLs from a special folder, and analyzing every class which inherits GameEngine .
But then came another thought into my mind...
What if someone, instead of implementing a game, inherits GameEngine and puts down malicious code into ProcessMessage() ?
My first solution is not to read DLLs from a directory, but to read only a DLL that I will code... Whenever I want to add another game, I would update the DLL...
However, this prevents other programmers from adding games to my program...
What can I do?
Thanks in advance,
Shy.
|
|
|
|
|
shyagam wrote: What if someone, instead of implementing a game, inherits GameEngine and puts down malicious code
A plugin system is per design an "open system", what means malicious code here?
First of all, the game user needs to download and install a plugin, so I would say if someone uses code from an unknown source he/she is generally responsible for caused damage! In case you just want to protect users from e.g. downloading broken plugins then have a checksum with each DLL that your downloader checks (i.e. SHA1 checksum does no match with DLL then delete it). Perhaps you can offer quality control to plugin developers and give a "verified" rating to decent plugins... or list good plugins on your webpage (e.g. see IrfanView)?
If your question is about limiting plugins from sources other than yourself: You could sign each DLL cryptographically or have an initial handshake with a "license" that enables certain functionality... but at the end of the day this can be technically circumvented since the algorithm/key is somewhere inside the plugin or the application. When I follow the PS/Wii/Xbox modding scene I think vendor locking attempts are quite futile...
Hope it helps.
|
|
|
|
|
Hello,
I am designing a Library Managment system for a school project. It includes 3 main constructs behind the UI:
Member - contains details about a member including a unique ID (using GUID's) and an array of Loan objects.
Book - contains details about a book, a unique ID and a reference to a single Loan object.
Loan - contains due date, issue date, unique ID and references to both the Member and Book which the loan is based upon.
Everything is fine up to here but once it comes to saving/loading this data problems appear. I want to have three seperate files, one which contains all the Books, one containing Members and a third containing all the Loans. Now the obvious way todo this would be to simply save the ID of the object if it is contained in a seperate file so for example the Loan object would be saved containing two GUIDs, one pointing to the Member and one pointing to the Book. That's all fine and dandy but when it comes to loading the files how should I approach creating the individual objects? I don't really want the complications of loading and saving to shine through in my object model as that would be bad design. Any suggestions? I am using C# to build this project by the way.
Thanks,
Daniel
|
|
|
|
|
You've raised some very interesting points, thank you. I have been thinking about this and as you say the Member and Book objects should not really need to be dependant upon the Loan object. I have now revised my object model:
Member - contains information about the member and a unique identifier.
Book - contains info about the book such as Title, ISBN, Author and a unique identifier.
Loan - a relationship between a Member and a Book with due date, issue date, etc.
To me it seems logical to use three seperate files. Why should the Members file have anything to do with the Book file, since they have no direct relationship without a Loan connecting them. Also I am considering using Serialization which would mean rewriting the whole file each time I save it - causing unnecessary overhead if I have to rewrite the usually static Members and Books.
Even with my new object model my original problem is not solved. If I am saving the Loans to a seperate file I will have to use the unique identifiers of the Books and Members to reference them. When I want to load the Loan objects again what would be the best way to go about this? Should I load the loan details and then loop through the Members and Books (which would be loaded first), until I find the correct object to reference for the Loan, and THEN create a real Loan object?
Thanks for your suggestions
Daniel
|
|
|
|
|
Sure,
1) It is a school project, but also a bit of a hobby project. (the requirements for our school project are very low so I'm trying to do something that challenges myself!)
2) I'd like to be able to scale to at least a thousand books and a few hundred members (I realize that pretty much rules out any sort of serialization as it's very slow). I know ideally I would use some soft of database, but part of the requirements for the project is that I use plain old files.
3) Definitely a single-user system, that can only be accessed by one person at a time.
Thanks
Daniel
|
|
|
|
|
Maybe a single XML file would be better suited to your needs.
Something like:
<library>
<members>
<!-- Member List -->
<member id="1" name="tristan"/>
</members>
<books>
<!-- Book List -->
<book id="1" author="me" name="mybook"/>
</books>
<loans>
<loan book="1" member="1"/>
<!-- Loan List -->
</loans>
</library>
You can then load the entire document into an object model, XmlDocument object, query it with XPath or many of the other xml operations. It also keeps the relations intact.
Hope that gives you some ideas.
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Hi
Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier
I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0)
Francois
Happy Coding!
|
|
|
|
|
instead of inehritance, you can use delegation (or aggregation), i.e. Class B will contain a reference to an instance of a class A object and delegate it to do the requested work. This way B will expos no A methods.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
If I understand you correctly you're saying "Dim o as new class-A" and then use "o.methodA" in class-B. I did think of this - but was wondering if there was another ("cleaner") way to skin the cat?
|
|
|
|
|
This is clean. Object aggregation it's often a good design alternative to complex class hierachies.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
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
|
|
|
|