Design pattern for configuring objects

Context

In a Cocoa application I am developing, I need to load a data model that is defined in plist files. So, I have something like:

root (Array)
---- item (Dictionary)
-------- name : "objects" (string)
-------- prefab : "object" (string)
-------- children : (Array)
...
---- item (Dictionary)
-------- name : "actions" (string)
-------- prefab : "action" (string)
-------- children : (Array)

So, the previous data model is loaded in the code to become an object representation using the language’s primitives (arrays, dictionaries, strings, … etc). No custom classes here. When I load that model, I know that an item in the table view can have children if the “prefab” key is set. When “add child” is pressed, I go to the prefabs (some other plist) and fetch that prefab’s structure. e.g:

root (Array)
---- item (Dictionary)
-------- name : "object" (string)
-------- parameters : (dictionary)
------------ key "object_id" : value ""
------------ key "x_position" : value 0
...

As you can see, from the prefab in the first model, I can go to the second plist and fetch a structure that is defined in a plist. All loaded using a plist library, without any subclass creation whatsoever. There is a single prefab factory class that contains the prefab structures, and instantiates and initializes the object from the prefab with the configuration data.

Problem

I hope you see the grave danger in this design. The model contains both user generated data as well as configuration data!! EEEEK!!! … Sheesh, that’s so bad…

The problem haunted me when I started exporting the model after the user of the app interacted with the model though the UI. The exported model would contain the configuration data (such as the prefab key), which makes the exported data rigid and un-upgradable. If I were to change the prefab key in later version of the app, to something else, and you load an old model, that model will load the old configurations with it, in our case, referencing the old prefab.

Question

I need help find a proper design pattern that clicks with this data driven design that I have, by providing the configuration data from a separate file, and somehow, linking it with the data model.

2

Funnily, while writing the question part of the post, I wrote this:

I can’t create subclass for each data entity (object, action, … etc), but I can create a generic subclass that fits all the objects.

That’s it!

Even though the prefab factory can configure the instantiated object on-the-fly, it can only do that when the object is created for the very first time. When it is loaded from the model, it is more or less de-serialized, which meant I had to traverse the model tree… Which was so ugly, I couldn’t write such code. Writing a custom subclass to rule them all, I can have it configure itself even when loaded from a serialized data model.

(Final remarks: I didn’t want all that typing in the question to go to waste, besides stackexchange promotes Q&A style spreading knowledge kinda thing, so, yay)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật