NSDictionaries versus custom objects with properties, what do you take?

I am writing an application that mainly uses 5 business units: A, BC, D and E

  • A has some properties and contains a list of B
  • B has some other properties and list C and list D's
  • C has some other properties and list D and list E
  • D has only a few properties
  • E has only a few properties

Inheritance between them does not exist. There is no real business logic; objects are created, filled, and then read-only, without further manipulation.

My natural coding style would be to go object-oriented and write classes for each of these objects, use NSArrays for lists, and synthesize these properties.

This will make the code readable.

But another approach also seems obvious: use only NSDictionaries and NSArrays and work with keys / values ​​instead of properties. It seems more efficient and somehow “closer” to iPhone-style programming for me ... but it obviously leads to less readable code. Another advantage is the lack of additional custom encoding / decoding for serialization (saving state to disk using JSON, ...) So on paper, this speaks of the latter approach, on the other hand, it still seems inconvenient NOT to use custom objects ...

? / ? /? " Apple"? ( Java/#).

+3
3

Java/# Cocoa . ( ).

- "-" - . , , , (, ). , , (, . - ? , , )

+4

, ( /) .

, NSDictionary, , , , .

+2

. , , , , , ( ).

Also specify a property to access the dictionary. Thus, if you need to quickly spread a new value to a specific area of ​​code from a dictionary (presumably a new value added by the server), you have such flexibility. Then, if callers make heavy use of the value, you can transfer it as a true property and get the completion and type checking of the property.

+1
source

Source: https://habr.com/ru/post/1705689/


All Articles