• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TheChubu

Downsides/upsides to these absurd ideas?

2 posts in this topic

So, I was thinking about taking some features a bit to the extreme, some "What if..." scenarios.

 

Say that I don't want to use "classical" inheritance at all. What would be the downside of relying on interfaces only?

 

First thing that comes to mind is the overhead of the vtables the JVM would have to use. Just skimmed over some things and seems like HotSpot uses a vtable for every kind of inheritance, but it still does more work for resolving abstract methods.

 

Second thing is repetition of code. If I say, well my IPosition GetX() method returns the position of the object in the X axis. It might aswell be exactly the same for 10 other classes that use that interface, but I'd have to implement it on every one of them separately instead of just inheriting the working method.

 

Instead of establishing a hierarchy of "Actor is a(inherits) SolidWorldObject" or "Actor has a(composition) SolidWorldObject" you'd have a "Actor implements SolidWorldObject" you could get rid of the hierarchy and be able to ask the Actor object directly for its position instead of asking to the SolidWorldObject inside the Actor.

 

On the other hand, everything using interfaces would make you able to do some cool stuff, like grouping things in collections without worrying of "can I cast this to that, is that child or parent of that other class" and so on.

 

It would make easier to get a more "data oriented" design with huge collections of objects and the program iterating over them with the same interface, again, without the obtuseness that some class hierarchies might have.

 

And other thing I thought is if it would be any different to replace all instanced object methods with static methods that have a reference as parameter.

 

Say, instead of calling vec.normalize(); You'd call, Vector4f.normalize(vec); Instead of calling player.getX() You'd call Actor.getX(player);

 

The object would only hold data whereas the class would hold the static methods to operate on such data.

 

I'm not quite sure but I guess that's how method calls are implemented when they're compiled. While the per-object method calls gives you a nice way to relate the method call with the object you're using. So I guess you'd be doing "compiler work" by doing the reference passing by yourself instead of relying of the per-object method call and the "this" keyword.

 

It all came out of me thinking what could I do to make my math library better (something I might ask for more directly on another thread). What do you think?

0

Share this post


Link to post
Share on other sites

Interfaces are typically coupled with Dependency Injection, which you seem to recognize.  Composition has to happen at some level.  When you kludge over an existing system (like Java's standard library, with it's rigid inheritance chain), wrapping big objects with DI is commonly done.  If you're instead architecting such a system, you have more options.

 

Notably, Component-Based Entity Systems.  We've had a recent surge of articles involving them, and this is exactly what they are for.  Rather than re-implement GetX() for every object that has an X-coordinate, or wrap an existing monolithic object that already does so as mentioned above, inject that simple behavior (or simple data structure in a pure component environment) in isolation.

 

IMO, this really captures the spirit of interfaces in the first place -- collections of functionality that are contractually required to be implemented in some fashion.  If you don't want to system-drive everything as in a pure gamedev-ish Component System, perhaps the Strategy Pattern would be a good place to look for inspiration.

 

Your second thing is basically how objects are implemented in C.  At some level, that's how most OOP works under the hood, as you suspect.  I wouldn't really examine Math libraries that way though -- math libraries are typically static classes (or namespaces with functions, whatever) because math, or at least the kind of math in simple math libraries, is typically stateless.  I don't think it has any utility in a real OO language though; C++ pretty much does this conversion for you at zero cost over implementing semantically the same thing in C.

Edited by SeraphLance
2

Share this post


Link to post
Share on other sites

Hm. I've just used a few interfaces for another project (just recently discovered fractal terrains) and ended up doing what you mentioned. Doing several getX,setX,getY,setY just didn't seemed nice at all. Made a few Position, Direction, etc objects, "composed" the others with them and thats it. Not so clean in the calling (this.particle.position.getX() looks kinda bad) but it halves the work I'd have to make if I was just using "IPosition" or "IDirection" interfaces.

 

I knew about the strategy patter by name only (I think it was mentioned in Effective Java) I'll read more about it!

 

About the class statics. Nah, I wasn't going to use that for my math library. Even the normalize method, which I've seen implemented directly in Vector objects, is a separate static method in my math class that receives a vector to normalize. Otherwise it would make my vector classes very complicated.

 

Thanks for your input.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0